public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExceptionResolver implements InitializingBean, ApplicationContextAware
AbstractHandlerMethodExceptionResolver
that resolves exceptions
through @ExceptionHandler
methods.
Support for custom argument and return value types can be added via
setCustomArgumentResolvers(java.util.List<org.springframework.web.method.support.HandlerMethodArgumentResolver>)
and setCustomReturnValueHandlers(java.util.List<org.springframework.web.method.support.HandlerMethodReturnValueHandler>)
.
Or alternatively to re-configure all argument and return value types use
setArgumentResolvers(java.util.List<org.springframework.web.method.support.HandlerMethodArgumentResolver>)
and setReturnValueHandlers(List)
.
Modifier and Type | Field and Description |
---|---|
private ApplicationContext |
applicationContext |
private HandlerMethodArgumentResolverComposite |
argumentResolvers |
private ContentNegotiationManager |
contentNegotiationManager |
private java.util.List<HandlerMethodArgumentResolver> |
customArgumentResolvers |
private java.util.List<HandlerMethodReturnValueHandler> |
customReturnValueHandlers |
private java.util.Map<ControllerAdviceBean,ExceptionHandlerMethodResolver> |
exceptionHandlerAdviceCache |
private java.util.Map<java.lang.Class<?>,ExceptionHandlerMethodResolver> |
exceptionHandlerCache |
private java.util.List<HttpMessageConverter<?>> |
messageConverters |
private HandlerMethodReturnValueHandlerComposite |
returnValueHandlers |
logger
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
ExceptionHandlerExceptionResolver()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied
(and satisfied BeanFactoryAware and ApplicationContextAware).
|
protected ModelAndView |
doResolveHandlerMethodException(HttpServletRequest request,
HttpServletResponse response,
HandlerMethod handlerMethod,
java.lang.Exception exception)
Find an
@ExceptionHandler method and invoke it to handle the raised exception. |
ApplicationContext |
getApplicationContext() |
HandlerMethodArgumentResolverComposite |
getArgumentResolvers()
Return the configured argument resolvers, or possibly
null if
not initialized yet via afterPropertiesSet() . |
java.util.List<HandlerMethodArgumentResolver> |
getCustomArgumentResolvers()
Return the custom argument resolvers, or
null . |
java.util.List<HandlerMethodReturnValueHandler> |
getCustomReturnValueHandlers()
Return the custom return value handlers, or
null . |
protected java.util.List<HandlerMethodArgumentResolver> |
getDefaultArgumentResolvers()
Return the list of argument resolvers to use including built-in resolvers
and custom resolvers provided via
setCustomArgumentResolvers(java.util.List<org.springframework.web.method.support.HandlerMethodArgumentResolver>) . |
protected java.util.List<HandlerMethodReturnValueHandler> |
getDefaultReturnValueHandlers()
Return the list of return value handlers to use including built-in and
custom handlers provided via
setReturnValueHandlers(java.util.List<org.springframework.web.method.support.HandlerMethodReturnValueHandler>) . |
protected ServletInvocableHandlerMethod |
getExceptionHandlerMethod(HandlerMethod handlerMethod,
java.lang.Exception exception)
Find an
@ExceptionHandler method for the given exception. |
java.util.List<HttpMessageConverter<?>> |
getMessageConverters()
Return the configured message body converters.
|
HandlerMethodReturnValueHandlerComposite |
getReturnValueHandlers()
Return the configured handlers, or possibly
null if not
initialized yet via afterPropertiesSet() . |
private void |
initExceptionHandlerAdviceCache() |
void |
setApplicationContext(ApplicationContext applicationContext)
Set the ApplicationContext that this object runs in.
|
void |
setArgumentResolvers(java.util.List<HandlerMethodArgumentResolver> argumentResolvers)
Configure the complete list of supported argument types thus overriding
the resolvers that would otherwise be configured by default.
|
void |
setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager)
Set the
ContentNegotiationManager to use to determine requested media types. |
void |
setCustomArgumentResolvers(java.util.List<HandlerMethodArgumentResolver> argumentResolvers)
Provide resolvers for custom argument types.
|
void |
setCustomReturnValueHandlers(java.util.List<HandlerMethodReturnValueHandler> returnValueHandlers)
Provide handlers for custom return value types.
|
void |
setMessageConverters(java.util.List<HttpMessageConverter<?>> messageConverters)
Set the message body converters to use.
|
void |
setReturnValueHandlers(java.util.List<HandlerMethodReturnValueHandler> returnValueHandlers)
Configure the complete list of supported return value types thus
overriding handlers that would otherwise be configured by default.
|
doResolveException, shouldApplyTo
buildLogMessage, getOrder, logException, prepareResponse, preventCaching, resolveException, setMappedHandlerClasses, setMappedHandlers, setOrder, setPreventResponseCaching, setWarnLogCategory
private java.util.List<HandlerMethodArgumentResolver> customArgumentResolvers
private java.util.List<HandlerMethodReturnValueHandler> customReturnValueHandlers
private java.util.List<HttpMessageConverter<?>> messageConverters
private ContentNegotiationManager contentNegotiationManager
private final java.util.Map<java.lang.Class<?>,ExceptionHandlerMethodResolver> exceptionHandlerCache
private final java.util.Map<ControllerAdviceBean,ExceptionHandlerMethodResolver> exceptionHandlerAdviceCache
private HandlerMethodArgumentResolverComposite argumentResolvers
private HandlerMethodReturnValueHandlerComposite returnValueHandlers
private ApplicationContext applicationContext
public ExceptionHandlerExceptionResolver()
public void setCustomArgumentResolvers(java.util.List<HandlerMethodArgumentResolver> argumentResolvers)
setArgumentResolvers(java.util.List<org.springframework.web.method.support.HandlerMethodArgumentResolver>)
instead.public java.util.List<HandlerMethodArgumentResolver> getCustomArgumentResolvers()
null
.public void setArgumentResolvers(java.util.List<HandlerMethodArgumentResolver> argumentResolvers)
public HandlerMethodArgumentResolverComposite getArgumentResolvers()
null
if
not initialized yet via afterPropertiesSet()
.public void setCustomReturnValueHandlers(java.util.List<HandlerMethodReturnValueHandler> returnValueHandlers)
setReturnValueHandlers(java.util.List<org.springframework.web.method.support.HandlerMethodReturnValueHandler>)
.public java.util.List<HandlerMethodReturnValueHandler> getCustomReturnValueHandlers()
null
.public void setReturnValueHandlers(java.util.List<HandlerMethodReturnValueHandler> returnValueHandlers)
public HandlerMethodReturnValueHandlerComposite getReturnValueHandlers()
null
if not
initialized yet via afterPropertiesSet()
.public void setMessageConverters(java.util.List<HttpMessageConverter<?>> messageConverters)
These converters are used to convert from and to HTTP requests and responses.
public java.util.List<HttpMessageConverter<?>> getMessageConverters()
public void setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager)
ContentNegotiationManager
to use to determine requested media types.
If not set, the default constructor is used.public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
ApplicationContextAware
Invoked after population of normal bean properties but before an init callback such
as InitializingBean.afterPropertiesSet()
or a custom init-method. Invoked after ResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader)
,
ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)
and
MessageSourceAware
, if applicable.
setApplicationContext
in interface ApplicationContextAware
applicationContext
- the ApplicationContext object to be used by this objectApplicationContextException
- in case of context initialization errorsBeansException
- if thrown by application context methodsBeanInitializationException
public ApplicationContext getApplicationContext()
public void afterPropertiesSet()
InitializingBean
This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.
afterPropertiesSet
in interface InitializingBean
protected java.util.List<HandlerMethodArgumentResolver> getDefaultArgumentResolvers()
setCustomArgumentResolvers(java.util.List<org.springframework.web.method.support.HandlerMethodArgumentResolver>)
.protected java.util.List<HandlerMethodReturnValueHandler> getDefaultReturnValueHandlers()
setReturnValueHandlers(java.util.List<org.springframework.web.method.support.HandlerMethodReturnValueHandler>)
.private void initExceptionHandlerAdviceCache()
protected ModelAndView doResolveHandlerMethodException(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod, java.lang.Exception exception)
@ExceptionHandler
method and invoke it to handle the raised exception.doResolveHandlerMethodException
in class AbstractHandlerMethodExceptionResolver
request
- current HTTP requestresponse
- current HTTP responsehandlerMethod
- the executed handler method, or null
if none chosen at the time
of the exception (for example, if multipart resolution failed)exception
- the exception that got thrown during handler executionnull
for default processingprotected ServletInvocableHandlerMethod getExceptionHandlerMethod(HandlerMethod handlerMethod, java.lang.Exception exception)
@ExceptionHandler
method for the given exception. The default
implementation searches methods in the class hierarchy of the controller first
and if not found, it continues searching for additional @ExceptionHandler
methods assuming some @ControllerAdvice
Spring-managed beans were detected.handlerMethod
- the method where the exception was raised, possibly null
exception
- the raised exceptionnull