public class

AnnotationMethodHandlerExceptionResolver

extends AbstractHandlerExceptionResolver
java.lang.Object
   ↳ org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver
     ↳ org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver

Class Overview

Implementation of the HandlerExceptionResolver interface that handles exceptions through the ExceptionHandler annotation.

This exception resolver is enabled by default in the DispatcherServlet.

Summary

[Expand]
Inherited Constants
From interface org.springframework.core.Ordered
[Expand]
Inherited Fields
From class org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver
Public Constructors
AnnotationMethodHandlerExceptionResolver()
Public Methods
void setCustomArgumentResolver(WebArgumentResolver argumentResolver)
Set a custom ArgumentResolvers to use for special method parameter types.
void setCustomArgumentResolvers(WebArgumentResolver[] argumentResolvers)
Set one or more custom ArgumentResolvers to use for special method parameter types.
void setMessageConverters(HttpMessageConverter[]<?> messageConverters)
Set the message body converters to use.
Protected Methods
ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, 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.
List<Class<? extends Throwable>> getHandledExceptions(Method method)
Returns all the exception classes handled by the given method.
Object resolveCommonArgument(MethodParameter methodParameter, NativeWebRequest webRequest, Exception thrownException)
Resolves common method arguments.
Object resolveStandardArgument(Class parameterType, NativeWebRequest webRequest, Exception thrownException)
Resolves standard method arguments.
[Expand]
Inherited Methods
From class org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver
From class java.lang.Object
From interface org.springframework.core.Ordered
From interface org.springframework.web.servlet.HandlerExceptionResolver

Public Constructors

public AnnotationMethodHandlerExceptionResolver ()

Public Methods

public void setCustomArgumentResolver (WebArgumentResolver argumentResolver)

Set a custom ArgumentResolvers to use for special method parameter types.

Such a custom ArgumentResolver will kick in first, having a chance to resolve an argument value before the standard argument handling kicks in.

public void setCustomArgumentResolvers (WebArgumentResolver[] argumentResolvers)

Set one or more custom ArgumentResolvers to use for special method parameter types.

Any such custom ArgumentResolver will kick in first, having a chance to resolve an argument value before the standard argument handling kicks in.

public void setMessageConverters (HttpMessageConverter[]<?> messageConverters)

Set the message body converters to use.

These converters are used to convert from and to HTTP requests and responses.

Protected Methods

protected ModelAndView doResolveException (HttpServletRequest request, HttpServletResponse response, Object handler, 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.

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.

Parameters
request current HTTP request
response current HTTP response
handler 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 execution
Returns
  • a corresponding ModelAndView to forward to, or null for default processing

protected List<Class<? extends Throwable>> getHandledExceptions (Method method)

Returns all the exception classes handled by the given method.

The default implementation looks for exceptions in the ExceptionHandler#value() annotation, or - if that annotation element is empty - any exceptions listed in the method parameters if the method is annotated with @ExceptionHandler.

Parameters
method the method
Returns
  • the handled exceptions

protected Object resolveCommonArgument (MethodParameter methodParameter, NativeWebRequest webRequest, Exception thrownException)

Resolves common method arguments. Delegates to registered argumentResolvers first, then checking resolveStandardArgument(Class, NativeWebRequest, Exception).

Parameters
methodParameter the method parameter
webRequest the request
thrownException the exception thrown
Returns
Throws
Exception

protected Object resolveStandardArgument (Class parameterType, NativeWebRequest webRequest, Exception thrownException)

Resolves standard method arguments. The default implementation handles NativeWebRequest, ServletRequest, ServletResponse, HttpSession, Principal, Locale, request InputStream, request Reader, response OutputStream, response Writer, and the given thrownException.

Parameters
parameterType the method parameter type
webRequest the request
thrownException the exception thrown
Returns
Throws
Exception