Does anybody know why I cannot use @ResponseStatus(reason = "My message")
on an exception handler in spring MVC while still returning a @ResponseBody. What seems to happen is that if I use the reason
attribute
// 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 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 reallyNotFoundHandler(ReallyNotFoundException e){
return Collections.singletonMap("message", e.getMessage());
}
The code for this example is over on github.