Spring引发抛出HttpMediaTypeNotAcceptableException:找不到可接受的表示

时间:2017-02-01 17:28:04

标签: spring-boot media-type

以下是我班上的2个映射:

@Override
@RequestMapping(value="/getUserDetails", consumes={"application/xml", "text/xml"}, produces={"application/xml", "text/xml"}, method = RequestMethod.POST)
@ResponseBody
@ApiOperation(httpMethod = "GET", value = "Response for user details", notes = "Gets response for user details", response = GetUserDetailsResponse.class )
@ApiResponse(code = 200, message = "returns response for user details")
@Timed(name = "http.userservice.getUserDetails", absolute = true)
public GetUserDetailsResponse getUserDetails(
    @RequestBody GetUserDetailsRequest request) throws ServiceException {
    GetUserDetailsResponse response = new GetUserDetailsResponse();
    String username = request.getUsername();
    User user = createUser(username);
    response.setUser(user);
    response.setUsername(username);
    return response;
}

@Override
@RequestMapping(value = "/", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "hello world" , response = String.class )
@ApiResponse(code = 200, message = "hello world")
public String helloWorld() {
    return "hello world";
}

当我请求localhost:8080/时, 我得到了适当的回应,即" hello world"。 " /"映射到下面的第二个方法。

但是当我通过localhost:8080/getUserDetails请求请求POST时,春天会抛出HttpMediaTypeNotAcceptableException

有什么想法吗?

以下是我作为POST请求的一部分发送的xml数据

<userDetailsRequest>
    <username>abc@cdk.com</username>
</userDetailsRequest>

0 个答案:

没有答案