Class ExceptionHandlerExceptionResolver
- All Implemented Interfaces:
- Aware,- InitializingBean,- ApplicationContextAware,- Ordered,- HandlerExceptionResolver
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).
- Since:
- 3.1
- Author:
- Rossen Stoyanchev, Juergen Hoeller, Sebastien Deleuze, Brian Clozel
- 
Field SummaryFields inherited from class org.springframework.web.servlet.handler.AbstractHandlerExceptionResolverloggerFields inherited from interface org.springframework.core.OrderedHIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.protected @Nullable ModelAndViewdoResolveHandlerMethodException(HttpServletRequest request, HttpServletResponse response, @Nullable HandlerMethod handlerMethod, Exception exception) Find an@ExceptionHandlermethod and invoke it to handle the raised exception.Return the configured argument resolvers, or possiblynullif not initialized yet viaafterPropertiesSet().Return the configuredContentNegotiationManager.Return the custom argument resolvers, ornull.Return the custom return value handlers, ornull.protected List<HandlerMethodArgumentResolver> Return the list of argument resolvers to use including built-in resolvers and custom resolvers provided viasetCustomArgumentResolvers(java.util.List<org.springframework.web.method.support.HandlerMethodArgumentResolver>).protected List<HandlerMethodReturnValueHandler> Return the list of return value handlers to use including built-in and custom handlers provided viasetReturnValueHandlers(java.util.List<org.springframework.web.method.support.HandlerMethodReturnValueHandler>).Return theconfiguredErrorResponse.Interceptor's.Return an unmodifiable Map with the@ControllerAdvicebeans discovered in the ApplicationContext.protected @Nullable ServletInvocableHandlerMethodgetExceptionHandlerMethod(@Nullable HandlerMethod handlerMethod, Exception exception, ServletWebRequest webRequest) Find an@ExceptionHandlermethod for the given exception.Return the configured message body converters.Return the configured handlers, or possiblynullif not initialized yet viaafterPropertiesSet().protected booleanWhether this resolver has global exception handlers, for example, not declared in the same class as theHandlerMethodthat raised the exception and therefore can apply to any handler.voidsetApplicationContext(@Nullable ApplicationContext applicationContext) Set the ApplicationContext that this object runs in.voidsetArgumentResolvers(@Nullable List<HandlerMethodArgumentResolver> argumentResolvers) Configure the complete list of supported argument types thus overriding the resolvers that would otherwise be configured by default.voidsetContentNegotiationManager(ContentNegotiationManager contentNegotiationManager) Set theContentNegotiationManagerto use to determine requested media types.voidsetCustomArgumentResolvers(@Nullable List<HandlerMethodArgumentResolver> argumentResolvers) Provide resolvers for custom argument types.voidsetCustomReturnValueHandlers(@Nullable List<HandlerMethodReturnValueHandler> returnValueHandlers) Provide handlers for custom return value types.voidsetErrorResponseInterceptors(List<ErrorResponse.Interceptor> interceptors) Configure a list ofErrorResponse.Interceptor's to apply when rendering an RFC 9457ProblemDetailerror response.voidsetMessageConverters(List<HttpMessageConverter<?>> messageConverters) Set the message body converters to use.voidsetResponseBodyAdvice(@Nullable List<ResponseBodyAdvice<?>> responseBodyAdvice) Add one or more components to be invoked after the execution of a controller method annotated with@ResponseBodyor returningResponseEntitybut before the body is written to the response with the selectedHttpMessageConverter.voidsetReturnValueHandlers(@Nullable List<HandlerMethodReturnValueHandler> returnValueHandlers) Configure the complete list of supported return value types thus overriding handlers that would otherwise be configured by default.protected booleanshouldApplyTo(HttpServletRequest request, @Nullable Object handler) Checks if the handler is aHandlerMethodor the resolver has global exception handlers and then delegates to the base class implementation of#shouldApplyTopassing the bean of theHandlerMethodif necessary.Methods inherited from class org.springframework.web.servlet.handler.AbstractHandlerMethodExceptionResolverdoResolveExceptionMethods inherited from class org.springframework.web.servlet.handler.AbstractHandlerExceptionResolveraddMappedHandlerClass, buildLogMessage, getMappedHandlerClasses, getOrder, hasHandlerMappings, logException, prepareResponse, preventCaching, resolveException, setMappedHandlerClasses, setMappedHandlerPredicate, setMappedHandlers, setOrder, setPreventResponseCaching, setWarnLogCategory
- 
Constructor Details- 
ExceptionHandlerExceptionResolverpublic ExceptionHandlerExceptionResolver()
 
- 
- 
Method Details- 
setCustomArgumentResolverspublic void setCustomArgumentResolvers(@Nullable List<HandlerMethodArgumentResolver> argumentResolvers) Provide resolvers for custom argument types. Custom resolvers are ordered after built-in ones. To override the built-in support for argument resolution usesetArgumentResolvers(java.util.List<org.springframework.web.method.support.HandlerMethodArgumentResolver>)instead.
- 
getCustomArgumentResolversReturn the custom argument resolvers, ornull.
- 
setArgumentResolversConfigure the complete list of supported argument types thus overriding the resolvers that would otherwise be configured by default.
- 
getArgumentResolversReturn the configured argument resolvers, or possiblynullif not initialized yet viaafterPropertiesSet().
- 
setCustomReturnValueHandlerspublic void setCustomReturnValueHandlers(@Nullable List<HandlerMethodReturnValueHandler> returnValueHandlers) Provide handlers for custom return value types. Custom handlers are ordered after built-in ones. To override the built-in support for return value handling usesetReturnValueHandlers(java.util.List<org.springframework.web.method.support.HandlerMethodReturnValueHandler>).
- 
getCustomReturnValueHandlersReturn the custom return value handlers, ornull.
- 
setReturnValueHandlerspublic void setReturnValueHandlers(@Nullable List<HandlerMethodReturnValueHandler> returnValueHandlers) Configure the complete list of supported return value types thus overriding handlers that would otherwise be configured by default.
- 
getReturnValueHandlersReturn the configured handlers, or possiblynullif not initialized yet viaafterPropertiesSet().
- 
setMessageConvertersSet the message body converters to use.These converters are used to convert from and to HTTP requests and responses. 
- 
getMessageConvertersReturn the configured message body converters.
- 
setContentNegotiationManagerSet theContentNegotiationManagerto use to determine requested media types. If not set, the default constructor is used.
- 
getContentNegotiationManagerReturn the configuredContentNegotiationManager.
- 
setResponseBodyAdviceAdd one or more components to be invoked after the execution of a controller method annotated with@ResponseBodyor returningResponseEntitybut before the body is written to the response with the selectedHttpMessageConverter.
- 
setErrorResponseInterceptorsConfigure a list ofErrorResponse.Interceptor's to apply when rendering an RFC 9457ProblemDetailerror response.- Parameters:
- interceptors- the handlers to use
- Since:
- 6.2
 
- 
getErrorResponseInterceptorsReturn theconfiguredErrorResponse.Interceptor's.- Since:
- 6.2
 
- 
setApplicationContextDescription copied from interface:ApplicationContextAwareSet the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.Invoked after population of normal bean properties but before an init callback such as InitializingBean.afterPropertiesSet()or a custom init-method. Invoked afterResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader),ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)andMessageSourceAware, if applicable.- Specified by:
- setApplicationContextin interface- ApplicationContextAware
- Parameters:
- applicationContext- the ApplicationContext object to be used by this object
- See Also:
 
- 
getApplicationContext
- 
afterPropertiesSetpublic void afterPropertiesSet()Description copied from interface:InitializingBeanInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set. - Specified by:
- afterPropertiesSetin interface- InitializingBean
 
- 
getExceptionHandlerAdviceCacheReturn an unmodifiable Map with the@ControllerAdvicebeans discovered in the ApplicationContext. The returned map will be empty if the method is invoked before the bean has been initialized viaafterPropertiesSet().
- 
getDefaultArgumentResolversReturn the list of argument resolvers to use including built-in resolvers and custom resolvers provided viasetCustomArgumentResolvers(java.util.List<org.springframework.web.method.support.HandlerMethodArgumentResolver>).
- 
getDefaultReturnValueHandlersReturn the list of return value handlers to use including built-in and custom handlers provided viasetReturnValueHandlers(java.util.List<org.springframework.web.method.support.HandlerMethodReturnValueHandler>).
- 
hasGlobalExceptionHandlersprotected boolean hasGlobalExceptionHandlers()Description copied from class:AbstractHandlerMethodExceptionResolverWhether this resolver has global exception handlers, for example, not declared in the same class as theHandlerMethodthat raised the exception and therefore can apply to any handler.- Overrides:
- hasGlobalExceptionHandlersin class- AbstractHandlerMethodExceptionResolver
 
- 
shouldApplyToDescription copied from class:AbstractHandlerMethodExceptionResolverChecks if the handler is aHandlerMethodor the resolver has global exception handlers and then delegates to the base class implementation of#shouldApplyTopassing the bean of theHandlerMethodif necessary. Otherwise, returnsfalse.- Overrides:
- shouldApplyToin class- AbstractHandlerMethodExceptionResolver
- Parameters:
- request- current HTTP request
- handler- the executed handler, or- nullif none chosen at the time of the exception (for example, if multipart resolution failed)
- Returns:
- whether this resolved should proceed with resolving the exception for the given request and handler
- See Also:
 
- 
doResolveHandlerMethodExceptionprotected @Nullable ModelAndView doResolveHandlerMethodException(HttpServletRequest request, HttpServletResponse response, @Nullable HandlerMethod handlerMethod, Exception exception) Find an@ExceptionHandlermethod and invoke it to handle the raised exception.- Specified by:
- doResolveHandlerMethodExceptionin class- AbstractHandlerMethodExceptionResolver
- Parameters:
- request- current HTTP request
- response- current HTTP response
- handlerMethod- the executed handler method, or- nullif none chosen at the time of the exception (for example, if multipart resolution failed)
- exception- the exception that got thrown during handler execution
- Returns:
- a corresponding ModelAndView to forward to, or nullfor default processing
 
- 
getExceptionHandlerMethodprotected @Nullable ServletInvocableHandlerMethod getExceptionHandlerMethod(@Nullable HandlerMethod handlerMethod, Exception exception, ServletWebRequest webRequest) Find an@ExceptionHandlermethod 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@ExceptionHandlermethods assuming some @ControllerAdvice Spring-managed beans were detected.- Parameters:
- handlerMethod- the method where the exception was raised (may be- null)
- exception- the raised exception
- webRequest- the original web request that resulted in a handler error
- Returns:
- a method to handle the exception, or nullif none
 
 
-