我使用Spring4来设计我的REST API。但是当我使用JsonDoc记录它时,它给出了一个错误:
服务器拒绝了此请求,因为请求实体位于 所请求的请求资源不支持的格式 方法
阿帕奇 Tomcat / 7.0.62
“,”状态“:415,”statusText“: “不支持的媒体类型”}
@ApiMethod
@ApiHeaders(headers={ @ApiHeader(name="Content-Type", allowedvalues="application/json",description="application/json")})
@RequestMapping(value="/test" ,method=RequestMethod.POST)
public @ApiResponseObject @ResponseBody ResponseMessage test(@ApiBodyObject @RequestBody TestDto test){
System.out.println(test.getId());
return testService.addTestMessage("hello demo");
}
我该如何测试?
答案 0 :(得分:0)
我相信它与JSONDoc无关。您需要检查是否发送了有效的Content-Type,如application / json。
还请检查TestDto JSON表示是否正确转换为JAVA对象。如果您的JSON字符串无法转换java对象,则Spring会抛出此错误。
如果您使用的是Jackson API,则可以使用以下示例来获取异常 并看到原因。
ssh -A -L 9000:ubuntu@my.private.instance.ip:22 ec2-user@my_nat_instance;
答案 1 :(得分:0)
检查您的内容类型并检查您的有效载荷格式。
可能有些属性不匹配。