Does anybody know why I cannot use @ResponseStatus(reason = \"My message\")
on an exception handler in spring MVC while still returning a @ResponseBody. What se
For the record, since Spring 3.2, this got even worse because the AnnotationMethodHandlerExceptionResolver
has been replaced by the ResponseStatusExceptionResolver
and it does:
protected ModelAndView resolveResponseStatus(ResponseStatus responseStatus, HttpServletRequest request,
HttpServletResponse response, Object handler, Exception ex) throws Exception {
int statusCode = responseStatus.value().value();
String reason = responseStatus.reason();
if (this.messageSource != null) {
reason = this.messageSource.getMessage(reason, null, reason, LocaleContextHolder.getLocale());
}
if (!StringUtils.hasLength(reason)) {
response.sendError(statusCode);
}
else {
response.sendError(statusCode, reason);
}
return new ModelAndView();
}
This is worth a bug report. Moreover, the @ResponseStatus
is documented with setStatus and is ill-designed. It should have been called @ResponseError
.
I have created two issues for this finally: SPR-11192 and SPR-11193.
Almost a year has passed and my two issues are still open. I do not consider Spring WebMVC as a first-class REST framework which it isn't imho, WebMVC is for humas and not machines :-(