类 DefaultHandlerExceptionResolver
- java.lang.Object
- org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver
- org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver
- 所有已实现的接口:
Ordered
,HandlerExceptionResolver
public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionResolver
The default implementation of theHandlerExceptionResolver
interface, resolving standard Spring MVC exceptions and translating them to corresponding HTTP status codes.This exception resolver is enabled by default in the common Spring
DispatcherServlet
.- 从以下版本开始:
- 3.0
- 作者:
- Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller
- 另请参阅:
ResponseEntityExceptionHandler
,handleNoSuchRequestHandlingMethod(org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
,handleHttpRequestMethodNotSupported(org.springframework.web.HttpRequestMethodNotSupportedException, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
,handleHttpMediaTypeNotSupported(org.springframework.web.HttpMediaTypeNotSupportedException, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
,handleMissingServletRequestParameter(org.springframework.web.bind.MissingServletRequestParameterException, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
,handleServletRequestBindingException(org.springframework.web.bind.ServletRequestBindingException, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
,handleTypeMismatch(org.springframework.beans.TypeMismatchException, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
,handleHttpMessageNotReadable(org.springframework.http.converter.HttpMessageNotReadableException, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
,handleHttpMessageNotWritable(org.springframework.http.converter.HttpMessageNotWritableException, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
,handleMethodArgumentNotValidException(org.springframework.web.bind.MethodArgumentNotValidException, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
,handleMissingServletRequestParameter(org.springframework.web.bind.MissingServletRequestParameterException, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
,handleMissingServletRequestPartException(org.springframework.web.multipart.support.MissingServletRequestPartException, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
,handleBindException(org.springframework.validation.BindException, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
字段概要
字段 修饰符和类型 字段 说明 static String
PAGE_NOT_FOUND_LOG_CATEGORY
Log category to use when no mapped handler is found for a request.protected static Log
pageNotFoundLogger
Additional logger to use when no mapped handler is found for a request.从类继承的字段 org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver
logger
从接口继承的字段 org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
构造器概要
构造器 构造器 说明 DefaultHandlerExceptionResolver()
Sets the order toOrdered.LOWEST_PRECEDENCE
.
方法概要
从类继承的方法 org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver
buildLogMessage, getOrder, logException, prepareResponse, preventCaching, resolveException, setMappedHandlerClasses, setMappedHandlers, setOrder, setPreventResponseCaching, setWarnLogCategory, shouldApplyTo
字段详细资料
PAGE_NOT_FOUND_LOG_CATEGORY
public static final String PAGE_NOT_FOUND_LOG_CATEGORY
Log category to use when no mapped handler is found for a request.- 另请参阅:
pageNotFoundLogger
, 常量字段值
pageNotFoundLogger
protected static final Log pageNotFoundLogger
Additional logger to use when no mapped handler is found for a request.
构造器详细资料
DefaultHandlerExceptionResolver
public DefaultHandlerExceptionResolver()
Sets the order toOrdered.LOWEST_PRECEDENCE
.
方法详细资料
doResolveException
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
从类复制的说明:AbstractHandlerExceptionResolver
Actually resolve the given exception that got thrown during handler execution, returning aModelAndView
that 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, ornull
if 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
ModelAndView
to forward to, ornull
for default processing in the resolution chain
handleNoSuchRequestHandlingMethod
@Deprecated protected ModelAndView handleNoSuchRequestHandlingMethod(NoSuchRequestHandlingMethodException ex, HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException
已过时。as of 4.3, along withNoSuchRequestHandlingMethodException
Handle the case where no request handler method was found.The default implementation logs a warning, sends an HTTP 404 error, and returns an empty
ModelAndView
. Alternatively, a fallback view could be chosen, or the NoSuchRequestHandlingMethodException could be rethrown as-is.- 参数:
ex
- the NoSuchRequestHandlingMethodException to be handledrequest
- current HTTP requestresponse
- current HTTP responsehandler
- the executed handler, ornull
if none chosen at the time of the exception (for example, if multipart resolution failed)- 返回:
- an empty ModelAndView indicating the exception was handled
- 抛出:
IOException
- potentially thrown fromHttpServletResponse.sendError(int, java.lang.String)
handleHttpRequestMethodNotSupported
protected ModelAndView handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex, HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException
Handle the case where no request handler method was found for the particular HTTP request method.The default implementation logs a warning, sends an HTTP 405 error, sets the "Allow" header, and returns an empty
ModelAndView
. Alternatively, a fallback view could be chosen, or the HttpRequestMethodNotSupportedException could be rethrown as-is.- 参数:
ex
- the HttpRequestMethodNotSupportedException to be handledrequest
- current HTTP requestresponse
- current HTTP responsehandler
- the executed handler, ornull
if none chosen at the time of the exception (for example, if multipart resolution failed)- 返回:
- an empty ModelAndView indicating the exception was handled
- 抛出:
IOException
- potentially thrown fromHttpServletResponse.sendError(int, java.lang.String)
handleHttpMediaTypeNotSupported
protected ModelAndView handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex, HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException
Handle the case where no message converters were found for the PUT or POSTed content.The default implementation sends an HTTP 415 error, sets the "Accept" header, and returns an empty
ModelAndView
. Alternatively, a fallback view could be chosen, or the HttpMediaTypeNotSupportedException could be rethrown as-is.- 参数:
ex
- the HttpMediaTypeNotSupportedException to be handledrequest
- current HTTP requestresponse
- current HTTP responsehandler
- the executed handler- 返回:
- an empty ModelAndView indicating the exception was handled
- 抛出:
IOException
- potentially thrown fromHttpServletResponse.sendError(int, java.lang.String)
handleHttpMediaTypeNotAcceptable
protected ModelAndView handleHttpMediaTypeNotAcceptable(HttpMediaTypeNotAcceptableException ex, HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException
Handle the case where no message converters were found that were acceptable for the client (expressed via theAccept
header.The default implementation sends an HTTP 406 error and returns an empty
ModelAndView
. Alternatively, a fallback view could be chosen, or the HttpMediaTypeNotAcceptableException could be rethrown as-is.- 参数:
ex
- the HttpMediaTypeNotAcceptableException to be handledrequest
- current HTTP requestresponse
- current HTTP responsehandler
- the executed handler- 返回:
- an empty ModelAndView indicating the exception was handled
- 抛出:
IOException
- potentially thrown fromHttpServletResponse.sendError(int, java.lang.String)
handleMissingPathVariable
protected ModelAndView handleMissingPathVariable(MissingPathVariableException ex, HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException
Handle the case when a declared path variable does not match any extracted URI variable.The default implementation sends an HTTP 500 error, and returns an empty
ModelAndView
. Alternatively, a fallback view could be chosen, or the MissingPathVariableException could be rethrown as-is.- 参数:
ex
- the MissingPathVariableException to be handledrequest
- current HTTP requestresponse
- current HTTP responsehandler
- the executed handler- 返回:
- an empty ModelAndView indicating the exception was handled
- 抛出:
IOException
- potentially thrown fromHttpServletResponse.sendError(int, java.lang.String)
- 从以下版本开始:
- 4.2
handleMissingServletRequestParameter
protected ModelAndView handleMissingServletRequestParameter(MissingServletRequestParameterException ex, HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException
Handle the case when a required parameter is missing.The default implementation sends an HTTP 400 error, and returns an empty
ModelAndView
. Alternatively, a fallback view could be chosen, or the MissingServletRequestParameterException could be rethrown as-is.- 参数:
ex
- the MissingServletRequestParameterException to be handledrequest
- current HTTP requestresponse
- current HTTP responsehandler
- the executed handler- 返回:
- an empty ModelAndView indicating the exception was handled
- 抛出:
IOException
- potentially thrown fromHttpServletResponse.sendError(int, java.lang.String)
handleServletRequestBindingException
protected ModelAndView handleServletRequestBindingException(ServletRequestBindingException ex, HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException
Handle the case when an unrecoverable binding exception occurs - e.g. required header, required cookie.The default implementation sends an HTTP 400 error, and returns an empty
ModelAndView
. Alternatively, a fallback view could be chosen, or the exception could be rethrown as-is.- 参数:
ex
- the exception to be handledrequest
- current HTTP requestresponse
- current HTTP responsehandler
- the executed handler- 返回:
- an empty ModelAndView indicating the exception was handled
- 抛出:
IOException
- potentially thrown fromHttpServletResponse.sendError(int, java.lang.String)
handleConversionNotSupported
protected ModelAndView handleConversionNotSupported(ConversionNotSupportedException ex, HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException
Handle the case when aWebDataBinder
conversion cannot occur.The default implementation sends an HTTP 500 error, and returns an empty
ModelAndView
. Alternatively, a fallback view could be chosen, or the ConversionNotSupportedException could be rethrown as-is.- 参数:
ex
- the ConversionNotSupportedException to be handledrequest
- current HTTP requestresponse
- current HTTP responsehandler
- the executed handler- 返回:
- an empty ModelAndView indicating the exception was handled
- 抛出:
IOException
- potentially thrown fromHttpServletResponse.sendError(int, java.lang.String)
handleTypeMismatch
protected ModelAndView handleTypeMismatch(TypeMismatchException ex, HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException
Handle the case when aWebDataBinder
conversion error occurs.The default implementation sends an HTTP 400 error, and returns an empty
ModelAndView
. Alternatively, a fallback view could be chosen, or the TypeMismatchException could be rethrown as-is.- 参数:
ex
- the TypeMismatchException to be handledrequest
- current HTTP requestresponse
- current HTTP responsehandler
- the executed handler- 返回:
- an empty ModelAndView indicating the exception was handled
- 抛出:
IOException
- potentially thrown fromHttpServletResponse.sendError(int, java.lang.String)
handleHttpMessageNotReadable
protected ModelAndView handleHttpMessageNotReadable(HttpMessageNotReadableException ex, HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException
Handle the case where a message converter cannot read from a HTTP request.The default implementation sends an HTTP 400 error, and returns an empty
ModelAndView
. Alternatively, a fallback view could be chosen, or the HttpMessageNotReadableException could be rethrown as-is.- 参数:
ex
- the HttpMessageNotReadableException to be handledrequest
- current HTTP requestresponse
- current HTTP responsehandler
- the executed handler- 返回:
- an empty ModelAndView indicating the exception was handled
- 抛出:
IOException
- potentially thrown fromHttpServletResponse.sendError(int, java.lang.String)
handleHttpMessageNotWritable
protected ModelAndView handleHttpMessageNotWritable(HttpMessageNotWritableException ex, HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException
Handle the case where a message converter cannot write to a HTTP request.The default implementation sends an HTTP 500 error, and returns an empty
ModelAndView
. Alternatively, a fallback view could be chosen, or the HttpMessageNotWritableException could be rethrown as-is.- 参数:
ex
- the HttpMessageNotWritableException to be handledrequest
- current HTTP requestresponse
- current HTTP responsehandler
- the executed handler- 返回:
- an empty ModelAndView indicating the exception was handled
- 抛出:
IOException
- potentially thrown fromHttpServletResponse.sendError(int, java.lang.String)
handleMethodArgumentNotValidException
protected ModelAndView handleMethodArgumentNotValidException(MethodArgumentNotValidException ex, HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException
Handle the case where an argument annotated with@Valid
such as anRequestBody
orRequestPart
argument fails validation.By default, an HTTP 400 error is sent back to the client.
- 参数:
request
- current HTTP requestresponse
- current HTTP responsehandler
- the executed handler- 返回:
- an empty ModelAndView indicating the exception was handled
- 抛出:
IOException
- potentially thrown fromHttpServletResponse.sendError(int, java.lang.String)
handleMissingServletRequestPartException
protected ModelAndView handleMissingServletRequestPartException(MissingServletRequestPartException ex, HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException
Handle the case where an @RequestPart, aMultipartFile
, or ajavax.servlet.http.Part
argument is required but is missing.By default, an HTTP 400 error is sent back to the client.
- 参数:
request
- current HTTP requestresponse
- current HTTP responsehandler
- the executed handler- 返回:
- an empty ModelAndView indicating the exception was handled
- 抛出:
IOException
- potentially thrown fromHttpServletResponse.sendError(int, java.lang.String)
handleBindException
protected ModelAndView handleBindException(BindException ex, HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException
Handle the case where an @ModelAttribute method argument has binding or validation errors and is not followed by another method argument of typeBindingResult
.By default, an HTTP 400 error is sent back to the client.
- 参数:
request
- current HTTP requestresponse
- current HTTP responsehandler
- the executed handler- 返回:
- an empty ModelAndView indicating the exception was handled
- 抛出:
IOException
- potentially thrown fromHttpServletResponse.sendError(int, java.lang.String)
handleNoHandlerFoundException
protected ModelAndView handleNoHandlerFoundException(NoHandlerFoundException ex, HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException
Handle the case where no handler was found during the dispatch.The default implementation sends an HTTP 404 error and returns an empty
ModelAndView
. Alternatively, a fallback view could be chosen, or the NoHandlerFoundException could be rethrown as-is.- 参数:
ex
- the NoHandlerFoundException to be handledrequest
- current HTTP requestresponse
- current HTTP responsehandler
- the executed handler, ornull
if none chosen at the time of the exception (for example, if multipart resolution failed)- 返回:
- an empty ModelAndView indicating the exception was handled
- 抛出:
IOException
- potentially thrown fromHttpServletResponse.sendError(int, java.lang.String)
- 从以下版本开始:
- 4.0
handleAsyncRequestTimeoutException
protected ModelAndView handleAsyncRequestTimeoutException(AsyncRequestTimeoutException ex, HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException
Handle the case where an async request timed out.The default implementation sends an HTTP 503 error.
- 参数:
ex
- theAsyncRequestTimeoutException
to be handledrequest
- current HTTP requestresponse
- current HTTP responsehandler
- the executed handler, ornull
if none chosen at the time of the exception (for example, if multipart resolution failed)- 返回:
- an empty ModelAndView indicating the exception was handled
- 抛出:
IOException
- potentially thrown fromHttpServletResponse.sendError(int, java.lang.String)
- 从以下版本开始:
- 4.2.8
sendServerError
protected void sendServerError(Exception ex, HttpServletRequest request, HttpServletResponse response) throws IOException
Invoked to send a server error. Sets the status to 500 and also sets the request attribute "javax.servlet.error.exception" to the Exception.- 抛出:
IOException