类 ResponseStatusExceptionResolver
- java.lang.Object
- org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver
- org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver
- 所有已实现的接口:
Aware,MessageSourceAware,Ordered,HandlerExceptionResolver
public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionResolver implements MessageSourceAware
AHandlerExceptionResolverthat uses the@ResponseStatusannotation to map exceptions to HTTP status codes.This exception resolver is enabled by default in the
DispatcherServletand the MVC Java config and the MVC namespace.As of 4.2 this resolver also looks recursively for
@ResponseStatuspresent on cause exceptions, and as of 4.2.2 this resolver supports attribute overrides for@ResponseStatusin custom composed annotations.As of 5.0 this resolver also supports
ResponseStatusException.- 从以下版本开始:
- 3.0
- 作者:
- Arjen Poutsma, Rossen Stoyanchev, Sam Brannen
- 另请参阅:
ResponseStatus,ResponseStatusException
字段概要
从类继承的字段 org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver
logger
从接口继承的字段 org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
构造器概要
构造器 构造器 说明 ResponseStatusExceptionResolver()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected ModelAndViewapplyStatusAndReason(int statusCode, String reason, HttpServletResponse response)Apply the resolved status code and reason to the response.protected ModelAndViewdoResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)Actually resolve the given exception that got thrown during handler execution, returning aModelAndViewthat represents a specific error page if appropriate.protected ModelAndViewresolveResponseStatus(ResponseStatus responseStatus, HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)Template method that handles the@ResponseStatusannotation.protected ModelAndViewresolveResponseStatusException(ResponseStatusException ex, HttpServletRequest request, HttpServletResponse response, Object handler)Template method that handles anResponseStatusException.voidsetMessageSource(MessageSource messageSource)Set the MessageSource that this object runs in.从类继承的方法 org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver
buildLogMessage, getOrder, logException, prepareResponse, preventCaching, resolveException, setMappedHandlerClasses, setMappedHandlers, setOrder, setPreventResponseCaching, setWarnLogCategory, shouldApplyTo
构造器详细资料
ResponseStatusExceptionResolver
public ResponseStatusExceptionResolver()
方法详细资料
setMessageSource
public void setMessageSource(MessageSource messageSource)
从接口复制的说明:MessageSourceAwareSet the MessageSource that this object runs in.Invoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method. Invoked before ApplicationContextAware's setApplicationContext.
- 指定者:
setMessageSource在接口中MessageSourceAware- 参数:
messageSource- message source to be used by this object
doResolveException
@Nullable protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, @Nullable Object handler, Exception ex)
从类复制的说明:AbstractHandlerExceptionResolverActually resolve the given exception that got thrown during handler execution, returning aModelAndViewthat 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.
- 指定者:
doResolveException在类中AbstractHandlerExceptionResolver- 参数:
request- current HTTP requestresponse- current HTTP responsehandler- the executed handler, ornullif none chosen at the time of the exception (for example, if multipart resolution failed)ex- the exception that got thrown during handler execution- 返回:
- a corresponding
ModelAndViewto forward to, ornullfor default processing in the resolution chain
resolveResponseStatus
protected ModelAndView resolveResponseStatus(ResponseStatus responseStatus, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler, Exception ex) throws Exception
Template method that handles the@ResponseStatusannotation.The default implementation delegates to
applyStatusAndReason(int, java.lang.String, javax.servlet.http.HttpServletResponse)with the status code and reason from the annotation.- 参数:
responseStatus- the@ResponseStatusannotationrequest- current HTTP requestresponse- current HTTP responsehandler- the executed handler, ornullif none chosen at the time of the exception, e.g. if multipart resolution failedex- the exception- 返回:
- an empty ModelAndView, i.e. exception resolved
- 抛出:
Exception
resolveResponseStatusException
protected ModelAndView resolveResponseStatusException(ResponseStatusException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws Exception
Template method that handles anResponseStatusException.The default implementation applies the headers from
ResponseStatusException.getResponseHeaders()and delegates toapplyStatusAndReason(int, java.lang.String, javax.servlet.http.HttpServletResponse)with the status code and reason from the exception.- 参数:
ex- the exceptionrequest- current HTTP requestresponse- current HTTP responsehandler- the executed handler, ornullif none chosen at the time of the exception, e.g. if multipart resolution failed- 返回:
- an empty ModelAndView, i.e. exception resolved
- 抛出:
Exception- 从以下版本开始:
- 5.0
applyStatusAndReason
protected ModelAndView applyStatusAndReason(int statusCode, @Nullable String reason, HttpServletResponse response) throws IOException
Apply the resolved status code and reason to the response.The default implementation sends a response error using
HttpServletResponse.sendError(int)orHttpServletResponse.sendError(int, String)if there is a reason and then returns an empty ModelAndView.- 参数:
statusCode- the HTTP status codereason- the associated reason (may benullor empty)response- current HTTP response- 抛出:
IOException- 从以下版本开始:
- 5.0