HandlerExceptionResolver that uses the @ResponseStatus
annotation to map exceptions to HTTP status codes.
This exception resolver is enabled by default in the
DispatcherServlet
and the MVC Java config and the MVC namespace.
As of 4.2 this resolver also looks recursively for @ResponseStatus
present on cause exceptions, and as of 4.2.2 this resolver supports
attribute overrides for @ResponseStatus in custom composed annotations.
As of 5.0 this resolver also supports ResponseStatusException.
ResponseStatus, ResponseStatusException
| Modifier and Type | Field and Description |
|---|---|
| private MessageSource |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected ModelAndView | applyStatusAndReason(int
the HTTP status code statusCode, String the associated reason (may be reason, HttpServletResponse null or empty)current HTTP response response)Apply the resolved status code and reason to the response. |
| protected ModelAndView | doResolveException(HttpServletRequest
current HTTP request request, HttpServletResponse current HTTP response response, Object the executed handler, or handler, Exception null if none chosen at the time
of the exception (for example, if multipart resolution failed)the exception that got thrown during handler execution ex)Implements abstract org. Actually resolve the given exception that got thrown during handler execution,
returning a |
| protected ModelAndView | Returns: an empty ModelAndView, i.e. exception resolvedthe responseStatus, HttpServletRequest @ResponseStatus annotationcurrent HTTP request request, HttpServletResponse current HTTP response response, Object the executed handler, or handler, Exception null if none chosen at the
time of the exception, e.g. if multipart resolution failedthe exception ex)Template method that handles the |
| protected ModelAndView | Returns: an empty ModelAndView, i.e. exception resolvedthe exception ex, HttpServletRequest current HTTP request request, HttpServletResponse current HTTP response response, Object the executed handler, or handler)null if none chosen at the
time of the exception, e.g. if multipart resolution failedTemplate method that handles an |
| public void | setMessageSource(MessageSource
message source to be used by this object messageSource)Implements org. Set the Invoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method. |
| messageSource | back to summary |
|---|---|
| private MessageSource messageSource
| |
| ResponseStatusExceptionResolver | back to summary |
|---|---|
| public ResponseStatusExceptionResolver() | |
| applyStatusAndReason | back to summary |
|---|---|
| protected ModelAndView applyStatusAndReason(int statusCode, String reason, HttpServletResponse response) throws IOException Apply the resolved status code and reason to the response. The default implementation sends a response error using
| |
| doResolveException | back to summary |
|---|---|
| protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) Implements abstract org. Doc from org. Actually resolve the given exception that got thrown during handler execution,
returning a May be overridden in subclasses, in order to apply specific exception checks. Note that this template method will be invoked after checking whether this resolver applies ("mappedHandlers" etc), so an implementation may simply proceed with its actual exception handling.
| |
| resolveResponseStatus | back to summary |
|---|---|
| protected ModelAndView resolveResponseStatus(ResponseStatus responseStatus, HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception Template method that handles the The default implementation delegates to
| |
| resolveResponseStatusException | back to summary |
|---|---|
| protected ModelAndView resolveResponseStatusException(ResponseStatusException ex, HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception Template method that handles an The default implementation applies the headers from
| |
| setMessageSource | back to summary |
|---|---|
| public void setMessageSource(MessageSource messageSource) Implements org. Doc from org. Set the Invoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method. Invoked before ApplicationContextAware's setApplicationContext.
| |