public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExceptionResolver implements org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.InitializingBean
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)
.
logger
Constructor and Description |
---|
ExceptionHandlerExceptionResolver() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
protected ModelAndView |
doResolveHandlerMethodException(HttpServletRequest request,
HttpServletResponse response,
org.springframework.web.method.HandlerMethod handlerMethod,
Exception exception)
Find an
@ExceptionHandler method and invoke it to handle the raised exception. |
org.springframework.context.ApplicationContext |
getApplicationContext() |
org.springframework.web.method.support.HandlerMethodArgumentResolverComposite |
getArgumentResolvers()
Return the configured argument resolvers, or possibly
null if
not initialized yet via afterPropertiesSet() . |
org.springframework.web.accept.ContentNegotiationManager |
getContentNegotiationManager()
Return the configured
ContentNegotiationManager . |
List<org.springframework.web.method.support.HandlerMethodArgumentResolver> |
getCustomArgumentResolvers()
Return the custom argument resolvers, or
null . |
List<org.springframework.web.method.support.HandlerMethodReturnValueHandler> |
getCustomReturnValueHandlers()
Return the custom return value handlers, or
null . |
protected List<org.springframework.web.method.support.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 List<org.springframework.web.method.support.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>) . |
Map<org.springframework.web.method.ControllerAdviceBean,org.springframework.web.method.annotation.ExceptionHandlerMethodResolver> |
getExceptionHandlerAdviceCache()
Return an unmodifiable Map with the
@ControllerAdvice
beans discovered in the ApplicationContext. |
protected ServletInvocableHandlerMethod |
getExceptionHandlerMethod(org.springframework.web.method.HandlerMethod handlerMethod,
Exception exception)
Find an
@ExceptionHandler method for the given exception. |
List<org.springframework.http.converter.HttpMessageConverter<?>> |
getMessageConverters()
Return the configured message body converters.
|
org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite |
getReturnValueHandlers()
Return the configured handlers, or possibly
null if not
initialized yet via afterPropertiesSet() . |
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext) |
void |
setArgumentResolvers(List<org.springframework.web.method.support.HandlerMethodArgumentResolver> argumentResolvers)
Configure the complete list of supported argument types thus overriding
the resolvers that would otherwise be configured by default.
|
void |
setContentNegotiationManager(org.springframework.web.accept.ContentNegotiationManager contentNegotiationManager)
Set the
ContentNegotiationManager to use to determine requested media types. |
void |
setCustomArgumentResolvers(List<org.springframework.web.method.support.HandlerMethodArgumentResolver> argumentResolvers)
Provide resolvers for custom argument types.
|
void |
setCustomReturnValueHandlers(List<org.springframework.web.method.support.HandlerMethodReturnValueHandler> returnValueHandlers)
Provide handlers for custom return value types.
|
void |
setMessageConverters(List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters)
Set the message body converters to use.
|
void |
setResponseBodyAdvice(List<ResponseBodyAdvice<?>> responseBodyAdvice)
Add one or more components to be invoked after the execution of a controller
method annotated with
@ResponseBody or returning ResponseEntity
but before the body is written to the response with the selected
HttpMessageConverter . |
void |
setReturnValueHandlers(List<org.springframework.web.method.support.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
public void setCustomArgumentResolvers(@Nullable List<org.springframework.web.method.support.HandlerMethodArgumentResolver> argumentResolvers)
setArgumentResolvers(java.util.List<org.springframework.web.method.support.HandlerMethodArgumentResolver>)
instead.@Nullable public List<org.springframework.web.method.support.HandlerMethodArgumentResolver> getCustomArgumentResolvers()
null
.public void setArgumentResolvers(@Nullable List<org.springframework.web.method.support.HandlerMethodArgumentResolver> argumentResolvers)
@Nullable public org.springframework.web.method.support.HandlerMethodArgumentResolverComposite getArgumentResolvers()
null
if
not initialized yet via afterPropertiesSet()
.public void setCustomReturnValueHandlers(@Nullable List<org.springframework.web.method.support.HandlerMethodReturnValueHandler> returnValueHandlers)
setReturnValueHandlers(java.util.List<org.springframework.web.method.support.HandlerMethodReturnValueHandler>)
.@Nullable public List<org.springframework.web.method.support.HandlerMethodReturnValueHandler> getCustomReturnValueHandlers()
null
.public void setReturnValueHandlers(@Nullable List<org.springframework.web.method.support.HandlerMethodReturnValueHandler> returnValueHandlers)
@Nullable public org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite getReturnValueHandlers()
null
if not
initialized yet via afterPropertiesSet()
.public void setMessageConverters(List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters)
These converters are used to convert from and to HTTP requests and responses.
public List<org.springframework.http.converter.HttpMessageConverter<?>> getMessageConverters()
public void setContentNegotiationManager(org.springframework.web.accept.ContentNegotiationManager contentNegotiationManager)
ContentNegotiationManager
to use to determine requested media types.
If not set, the default constructor is used.public org.springframework.web.accept.ContentNegotiationManager getContentNegotiationManager()
ContentNegotiationManager
.public void setResponseBodyAdvice(@Nullable List<ResponseBodyAdvice<?>> responseBodyAdvice)
@ResponseBody
or returning ResponseEntity
but before the body is written to the response with the selected
HttpMessageConverter
.public void setApplicationContext(@Nullable org.springframework.context.ApplicationContext applicationContext)
setApplicationContext
in interface org.springframework.context.ApplicationContextAware
@Nullable public org.springframework.context.ApplicationContext getApplicationContext()
public void afterPropertiesSet()
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
public Map<org.springframework.web.method.ControllerAdviceBean,org.springframework.web.method.annotation.ExceptionHandlerMethodResolver> getExceptionHandlerAdviceCache()
@ControllerAdvice
beans discovered in the ApplicationContext. The returned map will be empty if
the method is invoked before the bean has been initialized via
afterPropertiesSet()
.protected List<org.springframework.web.method.support.HandlerMethodArgumentResolver> getDefaultArgumentResolvers()
setCustomArgumentResolvers(java.util.List<org.springframework.web.method.support.HandlerMethodArgumentResolver>)
.protected List<org.springframework.web.method.support.HandlerMethodReturnValueHandler> getDefaultReturnValueHandlers()
setReturnValueHandlers(java.util.List<org.springframework.web.method.support.HandlerMethodReturnValueHandler>)
.@Nullable protected ModelAndView doResolveHandlerMethodException(HttpServletRequest request, HttpServletResponse response, @Nullable org.springframework.web.method.HandlerMethod handlerMethod, 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 processing@Nullable protected ServletInvocableHandlerMethod getExceptionHandlerMethod(@Nullable org.springframework.web.method.HandlerMethod handlerMethod, 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 (may be null
)exception
- the raised exceptionnull
if none