在@ResponseBody異常處理程序使用@ResponseStatus(原因=「」)是否有人知道我爲什麼不能在春天MVC異常處理程序使用@ResponseStatus(reason = "My message")
,同時還返回@ResponseBody。有什麼事發生的是,如果我用reason
屬性Spring MVC的:在Tomcat中
// this exception handle works, the result is a 404 and the http body is the json serialised
// {"message", "the message"}
@ExceptionHandler
@ResponseStatus(value = HttpStatus.NOT_FOUND)
public Map<String, String> notFoundHandler(NotFoundException e){
return Collections.singletonMap("message", e.getMessage());
}
// this doesn't... the response is a 404 and the status line reads 'Really really not found'
// but the body is actually the standard Tomcat 404 page
@ExceptionHandler
@ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "Really really not found")
public Map<String, String> reallyNotFoundHandler(ReallyNotFoundException e){
return Collections.singletonMap("message", e.getMessage());
}
的code for this example是在GitHub上。
同樣的問題在這裏:http://stackoverflow.com/questions/ 29075160 /無responsebody - 返回 - 從-的ExceptionHandler功能於彈簧啓動應用程序部署,在 – 2015-03-26 06:19:35