¿Alguien sabe por qué no puedo usar @ResponseStatus(reason = "My message")
en un manejador de excepciones en Spring MVC mientras todavía devuelvo @ResponseBody. Lo que parece ocurrir es que si uso el atributo reason
Spring MVC: using @ResponseStatus (reason = '') en un manejador de excepciones @ResponseBody en 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());
}
El code for this example ha terminado en github.
Mismo problema aquí: http://stackoverflow.com/questions/ 29075160/no-responsebody-returned-from-exceptionhandler-in-spring-boot-app-deployed-in –