【发布时间】:2013-12-08 19:30:30
【问题描述】:
我已经设置了一个 Spring RESTful Web 服务,用于接收用户的用户名和密码。一直在关注Spring IO上的教程
我的服务设置为接受用户名和密码,如下所示:
@Controller
@RequestMapping("/users")
public class UserCommandController {
private static Logger log = LoggerFactory.getLogger(UserCommandController.class);
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity createUser(@RequestBody UserDetail userDetail, UriComponentsBuilder builder) {
User newUser = new User();
newUser.setEmail(userDetail.getEmail());
newUser.setPassword(userDetail.getPassword());
newUser.setUserName(userDetail.getUsername());
try {
UserFactory.getInstance().saveNewUser(newUser);
} catch(UserException ue) {
log.error("Saving user failed. Exception: "+ue.getMessage());
}
return new ResponseEntity(HttpStatus.OK);
}
}
我通过 Google chrome 插件 POSTMAN 向服务发送 POST 参数作为测试,但我得到“HTTP: 415..服务器拒绝此请求,因为请求实体的格式不受请求的资源支持用于请求的方法。"
有人知道我做错了什么吗?
【问题讨论】:
-
确定:你能在哪里解决它?我看到了同样的问题。
标签: spring rest spring-mvc