public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionResolver implements MessageSourceAware
HandlerExceptionResolver
interface that uses the @ResponseStatus
annotation to map exceptions to HTTP status codes.
This exception resolver is enabled by default in the DispatcherServlet
.
logger
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
ResponseStatusExceptionResolver() |
Modifier and Type | Method and Description |
---|---|
protected ModelAndView |
doResolveException(HttpServletRequest request,
HttpServletResponse response,
java.lang.Object handler,
java.lang.Exception ex)
Actually resolve the given exception that got thrown during on handler execution,
returning a ModelAndView that represents a specific error page if appropriate.
|
protected ModelAndView |
resolveResponseStatus(ResponseStatus responseStatus,
HttpServletRequest request,
HttpServletResponse response,
java.lang.Object handler,
java.lang.Exception ex)
Template method that handles
@ResponseStatus annotation. |
void |
setMessageSource(MessageSource messageSource)
Set the MessageSource that this object runs in.
|
buildLogMessage, getOrder, logException, prepareResponse, preventCaching, resolveException, setMappedHandlerClasses, setMappedHandlers, setOrder, setPreventResponseCaching, setWarnLogCategory, shouldApplyTo
public void setMessageSource(MessageSource messageSource)
MessageSourceAware
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.
setMessageSource
in interface MessageSourceAware
messageSource
- message sourceto be used by this objectprotected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, java.lang.Object handler, java.lang.Exception ex)
AbstractHandlerExceptionResolver
May be overridden in subclasses, in order to apply specific exception checks. Note that this template method will be invoked after checking whether this resolved applies ("mappedHandlers" etc), so an implementation may simply proceed with its actual exception handling.
doResolveException
in class AbstractHandlerExceptionResolver
request
- current HTTP requestresponse
- current HTTP responsehandler
- the executed handler, or null
if none chosen at the time
of the exception (for example, if multipart resolution failed)ex
- the exception that got thrown during handler executionnull
for default processingprotected ModelAndView resolveResponseStatus(ResponseStatus responseStatus, HttpServletRequest request, HttpServletResponse response, java.lang.Object handler, java.lang.Exception ex) throws java.lang.Exception
@ResponseStatus
annotation. Default implementation send a
response error using HttpServletResponse.sendError(int)
, or HttpServletResponse.sendError(int,
String)
if the annotation has a reason. Returns an empty ModelAndView.
responseStatus
- the annotationrequest
- current HTTP requestresponse
- current HTTP responsehandler
- the executed handler, or null
if none chosen at the time of the exception
(for example, if multipart resolution failed)ex
- the exception that got thrown during handler executionnull
for default processingjava.lang.Exception