【发布时间】:2016-12-15 21:55:07
【问题描述】:
我有一个使用 spring 注释抛出异常的端点,这是我的异常代码:
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public class MyException extends BaseApiException{
public MyException (String variable){
super("variable :"+variable+" can not be updated.");
}
}
当我使用邮递员测试 Rest 端点时,我得到了正确的结果和正确的状态码:
{
"errorType": "MyExption",
"message": "variable : XYZ can not be updated."
}
我的问题是当我尝试使用 restTemplate 调用服务时,我没有在响应中收到正文,这是我的代码:
ResponseEntity<Document> response;
RestTemplate restTemplate = new RestTemplate();
response = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.POST, entity, Document.class);
【问题讨论】: