类 ExceptionHandlerExceptionResolver
- java.lang.Object
- org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver
- org.springframework.web.servlet.handler.AbstractHandlerMethodExceptionResolver
- org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver
public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExceptionResolver implements ApplicationContextAware, InitializingBean
AnAbstractHandlerMethodExceptionResolverthat resolves exceptions through@ExceptionHandlermethods.Support for custom argument and return value types can be added via
setCustomArgumentResolvers(java.util.List<org.springframework.web.method.support.HandlerMethodArgumentResolver>)andsetCustomReturnValueHandlers(java.util.List<org.springframework.web.method.support.HandlerMethodReturnValueHandler>). Or alternatively to re-configure all argument and return value types usesetArgumentResolvers(java.util.List<org.springframework.web.method.support.HandlerMethodArgumentResolver>)andsetReturnValueHandlers(List).- 从以下版本开始:
- 3.1
- 作者:
- Rossen Stoyanchev, Juergen Hoeller
字段概要
从类继承的字段 org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver
logger
从接口继承的字段 org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
构造器概要
构造器 构造器 说明 ExceptionHandlerExceptionResolver()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidafterPropertiesSet()Invoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.protected ModelAndViewdoResolveHandlerMethodException(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod, Exception exception)Find an@ExceptionHandlermethod and invoke it to handle the raised exception.ApplicationContextgetApplicationContext()HandlerMethodArgumentResolverCompositegetArgumentResolvers()Return the configured argument resolvers, or possiblynullif not initialized yet viaafterPropertiesSet().ContentNegotiationManagergetContentNegotiationManager()Return the configuredContentNegotiationManager.List<HandlerMethodArgumentResolver>getCustomArgumentResolvers()Return the custom argument resolvers, ornull.List<HandlerMethodReturnValueHandler>getCustomReturnValueHandlers()Return the custom return value handlers, ornull.protected List<HandlerMethodArgumentResolver>getDefaultArgumentResolvers()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>getDefaultReturnValueHandlers()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>).Map<ControllerAdviceBean,ExceptionHandlerMethodResolver>getExceptionHandlerAdviceCache()Return an unmodifiable Map with the@ControllerAdvicebeans discovered in the ApplicationContext.protected ServletInvocableHandlerMethodgetExceptionHandlerMethod(HandlerMethod handlerMethod, Exception exception)Find an@ExceptionHandlermethod for the given exception.List<HttpMessageConverter<?>>getMessageConverters()Return the configured message body converters.HandlerMethodReturnValueHandlerCompositegetReturnValueHandlers()Return the configured handlers, or possiblynullif not initialized yet viaafterPropertiesSet().voidsetApplicationContext(ApplicationContext applicationContext)Set the ApplicationContext that this object runs in.voidsetArgumentResolvers(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(List<HandlerMethodArgumentResolver> argumentResolvers)Provide resolvers for custom argument types.voidsetCustomReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers)Provide handlers for custom return value types.voidsetMessageConverters(List<HttpMessageConverter<?>> messageConverters)Set the message body converters to use.voidsetResponseBodyAdvice(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(List<HandlerMethodReturnValueHandler> returnValueHandlers)Configure the complete list of supported return value types thus overriding handlers that would otherwise be configured by default.从类继承的方法 org.springframework.web.servlet.handler.AbstractHandlerMethodExceptionResolver
doResolveException, shouldApplyTo
从类继承的方法 org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver
buildLogMessage, getOrder, logException, prepareResponse, preventCaching, resolveException, setMappedHandlerClasses, setMappedHandlers, setOrder, setPreventResponseCaching, setWarnLogCategory
构造器详细资料
ExceptionHandlerExceptionResolver
public ExceptionHandlerExceptionResolver()
方法详细资料
setCustomArgumentResolvers
public 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.
getCustomArgumentResolvers
@Nullable public List<HandlerMethodArgumentResolver> getCustomArgumentResolvers()
Return the custom argument resolvers, ornull.
setArgumentResolvers
public void setArgumentResolvers(@Nullable List<HandlerMethodArgumentResolver> argumentResolvers)
Configure the complete list of supported argument types thus overriding the resolvers that would otherwise be configured by default.
getArgumentResolvers
@Nullable public HandlerMethodArgumentResolverComposite getArgumentResolvers()
Return the configured argument resolvers, or possiblynullif not initialized yet viaafterPropertiesSet().
setCustomReturnValueHandlers
public 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>).
getCustomReturnValueHandlers
@Nullable public List<HandlerMethodReturnValueHandler> getCustomReturnValueHandlers()
Return the custom return value handlers, ornull.
setReturnValueHandlers
public 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.
getReturnValueHandlers
@Nullable public HandlerMethodReturnValueHandlerComposite getReturnValueHandlers()
Return the configured handlers, or possiblynullif not initialized yet viaafterPropertiesSet().
setMessageConverters
public void setMessageConverters(List<HttpMessageConverter<?>> messageConverters)
Set the message body converters to use.These converters are used to convert from and to HTTP requests and responses.
getMessageConverters
public List<HttpMessageConverter<?>> getMessageConverters()
Return the configured message body converters.
setContentNegotiationManager
public void setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager)
Set theContentNegotiationManagerto use to determine requested media types. If not set, the default constructor is used.
getContentNegotiationManager
public ContentNegotiationManager getContentNegotiationManager()
Return the configuredContentNegotiationManager.
setResponseBodyAdvice
public void setResponseBodyAdvice(@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.
setApplicationContext
public void setApplicationContext(@Nullable ApplicationContext applicationContext)
从接口复制的说明: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.- 指定者:
setApplicationContext在接口中ApplicationContextAware- 参数:
applicationContext- the ApplicationContext object to be used by this object- 另请参阅:
BeanInitializationException
getApplicationContext
@Nullable public ApplicationContext getApplicationContext()
afterPropertiesSet
public void afterPropertiesSet()
从接口复制的说明: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.
- 指定者:
afterPropertiesSet在接口中InitializingBean
getExceptionHandlerAdviceCache
public Map<ControllerAdviceBean,ExceptionHandlerMethodResolver> getExceptionHandlerAdviceCache()
Return 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().
getDefaultArgumentResolvers
protected List<HandlerMethodArgumentResolver> getDefaultArgumentResolvers()
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>).
getDefaultReturnValueHandlers
protected List<HandlerMethodReturnValueHandler> getDefaultReturnValueHandlers()
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>).
doResolveHandlerMethodException
@Nullable protected ModelAndView doResolveHandlerMethodException(HttpServletRequest request, HttpServletResponse response, @Nullable HandlerMethod handlerMethod, Exception exception)
Find an@ExceptionHandlermethod and invoke it to handle the raised exception.- 指定者:
doResolveHandlerMethodException在类中AbstractHandlerMethodExceptionResolver- 参数:
request- current HTTP requestresponse- current HTTP responsehandlerMethod- the executed handler method, ornullif none chosen at the time of the exception (for example, if multipart resolution failed)exception- the exception that got thrown during handler execution- 返回:
- a corresponding ModelAndView to forward to, or
nullfor default processing
getExceptionHandlerMethod
@Nullable protected ServletInvocableHandlerMethod getExceptionHandlerMethod(@Nullable HandlerMethod handlerMethod, Exception exception)
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.- 参数:
handlerMethod- the method where the exception was raised (may benull)exception- the raised exception- 返回:
- a method to handle the exception, or
nullif none