Rest Post Service返回错误代码415

时间:2016-09-27 17:58:51

标签: json rest soapui

我是Rest的新手。我在网上用例子写了一个简单的程序。

然而,当我使用soapui(rest)来调用时,我得到错误415

 {
   "timestamp": 1474998766661,
   "status": 415,
   "error": "Unsupported Media Type",
   "exception": "org.springframework.web.HttpMediaTypeNotSupportedException",
   "message": "Unsupported Media Type",
   "path": "/user"
}
@RestController
public class testController {

@RequestMapping(value = "/user", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody User createUser(@RequestBody @Valid final User user) {
    System.out.println("firstname: " + user.getFirstname());
    System.out.println("lastname: " + user.getLastname());
    return new User();
}
}


public class User {
private String firstname;
private String lastname;

public User() {
}

public User(String firstname, String lastname) {
    this.firstname = firstname;
    this.lastname = lastname;
}

public String getFirstname() {
    return firstname;
}
public void setFirstname(String firstname) {
    this.firstname = firstname;
}
public String getLastname() {
    return lastname;
}
public void setLastname(String lastname) {
    this.lastname = lastname;
}

}

1 个答案:

答案 0 :(得分:1)

将请求Content-Type设置为“application / json”。