diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolver.java index ae7a851d00..48e3516eb8 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolver.java @@ -29,10 +29,16 @@ import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver; /** - * Implementation of the {@link org.springframework.web.servlet.HandlerExceptionResolver HandlerExceptionResolver} - * interface that uses the {@link ResponseStatus @ResponseStatus} annotation to map exceptions to HTTP status codes. + * A {@link org.springframework.web.servlet.HandlerExceptionResolver + * HandlerExceptionResolver} that uses the {@link ResponseStatus @ResponseStatus} + * annotation to map exceptions to HTTP status codes. * - *

This exception resolver is enabled by default in the {@link org.springframework.web.servlet.DispatcherServlet}. + *

This exception resolver is enabled by default in the + * {@link org.springframework.web.servlet.DispatcherServlet DispatcherServlet} + * and the MVC Java config and the MVC namespace. + * + *

As of 4.2 this resolver also looks recursively for {@code @ResponseStatus} + * present on cause exceptions. * * @author Arjen Poutsma * @author Rossen Stoyanchev @@ -69,16 +75,22 @@ public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionRes } /** - * Template method that handles {@link ResponseStatus @ResponseStatus} annotation.

Default implementation send a - * response error using {@link HttpServletResponse#sendError(int)}, or {@link HttpServletResponse#sendError(int, - * String)} if the annotation has a {@linkplain ResponseStatus#reason() reason}. Returns an empty ModelAndView. + * Template method that handles {@link ResponseStatus @ResponseStatus} annotation. + * + *

Default implementation send a response error using + * {@link HttpServletResponse#sendError(int)} or + * {@link HttpServletResponse#sendError(int, String)} if the annotation has a + * {@linkplain ResponseStatus#reason() reason} and then returns an empty ModelAndView. + * * @param responseStatus the annotation * @param request current HTTP request * @param response current HTTP response - * @param handler the executed handler, or {@code null} if none chosen at the time of the exception - * (for example, if multipart resolution failed) - * @param ex the exception that got thrown during handler execution - * @return a corresponding ModelAndView to forward to, or {@code null} for default processing + * @param handler the executed handler, or {@code null} if none chosen at the + * time of the exception (for example, if multipart resolution failed) + * @param ex the exception that got thrown during handler execution or the + * exception that has the ResponseStatus annotation if found on the cause. + * @return a corresponding ModelAndView to forward to, or {@code null} + * for default processing */ protected ModelAndView resolveResponseStatus(ResponseStatus responseStatus, HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {