Top Description Fields Constructors Methods
org.springframework.web.servlet.mvc.support

public Class DefaultHandlerExceptionResolver

extends AbstractHandlerExceptionResolver
Class Inheritance
Imports
java.io.IOException, jakarta.servlet.http.HttpServletRequest, .HttpServletResponse, org.apache.commons.logging.Log, .LogFactory, org.springframework.beans.ConversionNotSupportedException, .TypeMismatchException, org.springframework.core.Ordered, org.springframework.http.HttpHeaders, .ProblemDetail, org.springframework.http.converter.HttpMessageNotReadableException, .HttpMessageNotWritableException, org.springframework.lang.Nullable, org.springframework.validation.BindException, .BindingResult, org.springframework.validation.method.MethodValidationException, org.springframework.web.ErrorResponse, .HttpMediaTypeNotAcceptableException, .HttpMediaTypeNotSupportedException, .HttpRequestMethodNotSupportedException, org.springframework.web.bind.MethodArgumentNotValidException, .MissingPathVariableException, .MissingServletRequestParameterException, .ServletRequestBindingException, org.springframework.web.bind.annotation.ModelAttribute, .RequestBody, .RequestPart, org.springframework.web.context.request.async.AsyncRequestTimeoutException, org.springframework.web.method.annotation.HandlerMethodValidationException, org.springframework.web.multipart.MultipartFile, org.springframework.web.multipart.support.MissingServletRequestPartException, org.springframework.web.servlet.ModelAndView, .NoHandlerFoundException, org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver, org.springframework.web.servlet.resource.NoResourceFoundException, org.springframework.web.util.WebUtils

The default implementation of the org.springframework.web.servlet.HandlerExceptionResolver 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 org.springframework.web.servlet.DispatcherServlet.

Supported Exceptions

Exception HTTP Status Code
HttpRequestMethodNotSupportedException
405 (SC_METHOD_NOT_ALLOWED)
HttpMediaTypeNotSupportedException
415 (SC_UNSUPPORTED_MEDIA_TYPE)
HttpMediaTypeNotAcceptableException
406 (SC_NOT_ACCEPTABLE)
MissingPathVariableException
500 (SC_INTERNAL_SERVER_ERROR)
MissingServletRequestParameterException
400 (SC_BAD_REQUEST)
MissingServletRequestPartException
400 (SC_BAD_REQUEST)
ServletRequestBindingException
400 (SC_BAD_REQUEST)
ConversionNotSupportedException
500 (SC_INTERNAL_SERVER_ERROR)
TypeMismatchException
400 (SC_BAD_REQUEST)
HttpMessageNotReadableException
400 (SC_BAD_REQUEST)
HttpMessageNotWritableException
500 (SC_INTERNAL_SERVER_ERROR)
MethodArgumentNotValidException
400 (SC_BAD_REQUEST)
400 (SC_BAD_REQUEST)
NoHandlerFoundException
404 (SC_NOT_FOUND)
NoResourceFoundException
404 (SC_NOT_FOUND)
AsyncRequestTimeoutException
503 (SC_SERVICE_UNAVAILABLE)
500 (SC_INTERNAL_SERVER_ERROR)
Authors
Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller
Since
3.0
See Also
org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler

Field Summary

Modifier and TypeField and Description
public static final String
PAGE_NOT_FOUND_LOG_CATEGORY

Log category to use when no mapped handler is found for a request.

protected static final Log
pageNotFoundLogger

Additional logger to use when no mapped handler is found for a request.

Inherited from org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver:
logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected ModelAndView
doResolveException(HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
,
Object
the executed handler, or null if none chosen at the time of the exception (for example, if multipart resolution failed)
handler
,
Exception
the exception that got thrown during handler execution
ex
)

Implements abstract org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.doResolveException.

Actually resolve the given exception that got thrown during handler execution, returning a ModelAndView that represents a specific error page if appropriate.

protected ModelAndView

Returns:

an empty ModelAndView indicating the exception was handled, or null indicating the exception should be handled in handleErrorResponse
handleAsyncRequestTimeoutException
(AsyncRequestTimeoutException ex, HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
,
Object
the executed handler, or null if none chosen at the time of the exception (for example, if multipart resolution failed)
handler
)

Handle the case where an async request timed out.

protected ModelAndView

Returns:

an empty ModelAndView indicating the exception was handled
handleBindException
(BindException ex, HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
,
Object
the executed handler
handler
)
Deprecated for removal since 6.0. as of 6.0 since org.springframework.web.method.annotation.ModelAttributeMethodProcessor now raises the MethodArgumentNotValidException subclass instead.

Handle the case where an @ModelAttribute method argument has binding or validation errors and is not followed by another method argument of type BindingResult.

protected ModelAndView

Returns:

an empty ModelAndView indicating the exception was handled
handleConversionNotSupported
(ConversionNotSupportedException
the ConversionNotSupportedException to be handled
ex
,
HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
,
Object
the executed handler
handler
)

Handle the case when a org.springframework.web.bind.WebDataBinder conversion cannot occur.

protected ModelAndView

Returns:

an empty ModelAndView indicating the exception was handled
handleErrorResponse
(ErrorResponse
the exception to be handled
errorResponse
,
HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
,
Object
the executed handler
handler
)

Handle an ErrorResponse exception.

protected ModelAndView

Returns:

an empty ModelAndView indicating the exception was handled, or null indicating the exception should be handled in handleErrorResponse
handleHandlerMethodValidationException
(HandlerMethodValidationException
the exception to be handled
ex
,
HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
,
Object
the executed handler
handler
)

Handle the case where method validation for a controller method failed.

protected ModelAndView

Returns:

an empty ModelAndView indicating the exception was handled, or null indicating the exception should be handled in handleErrorResponse
handleHttpMediaTypeNotAcceptable
(HttpMediaTypeNotAcceptableException
the HttpMediaTypeNotAcceptableException to be handled
ex
,
HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
,
Object
the executed handler
handler
)

Handle the case where no message converters were found that were acceptable for the client (expressed via the Accept header).

protected ModelAndView

Returns:

an empty ModelAndView indicating the exception was handled, or null indicating the exception should be handled in handleErrorResponse
handleHttpMediaTypeNotSupported
(HttpMediaTypeNotSupportedException
the HttpMediaTypeNotSupportedException to be handled
ex
,
HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
,
Object
the executed handler
handler
)

Handle the case where no message converters were found for PUT or POSTed content.

protected ModelAndView

Returns:

an empty ModelAndView indicating the exception was handled
handleHttpMessageNotReadable
(HttpMessageNotReadableException
the HttpMessageNotReadableException to be handled
ex
,
HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
,
Object
the executed handler
handler
)

Handle the case where a message converter cannot read from an HTTP request.

protected ModelAndView

Returns:

an empty ModelAndView indicating the exception was handled
handleHttpMessageNotWritable
(HttpMessageNotWritableException
the HttpMessageNotWritableException to be handled
ex
,
HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
,
Object
the executed handler
handler
)

Handle the case where a message converter cannot write to an HTTP response.

protected ModelAndView

Returns:

an empty ModelAndView indicating the exception was handled, or null indicating the exception should be handled in handleErrorResponse
handleHttpRequestMethodNotSupported
(HttpRequestMethodNotSupportedException
the HttpRequestMethodNotSupportedException to be handled
ex
,
HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
,
Object
the executed handler, or null if none chosen at the time of the exception (for example, if multipart resolution failed)
handler
)

Handle the case where no handler was found for the HTTP method.

protected ModelAndView

Returns:

an empty ModelAndView indicating the exception was handled, or null indicating the exception should be handled in handleErrorResponse
handleMethodArgumentNotValidException
(MethodArgumentNotValidException ex, HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
,
Object
the executed handler
handler
)

Handle the case where an argument annotated with @Valid such as an RequestBody or RequestPart argument fails validation.

protected ModelAndView

Returns:

an empty ModelAndView indicating the exception was handled
handleMethodValidationException
(MethodValidationException
the exception to be handled
ex
,
HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
,
Object
the executed handler
handler
)

Handle the case where method validation failed on a component that is not a web controller, e.g. on some underlying service.

protected ModelAndView

Returns:

an empty ModelAndView indicating the exception was handled, or null indicating the exception should be handled in handleErrorResponse
handleMissingPathVariable
(MissingPathVariableException
the MissingPathVariableException to be handled
ex
,
HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
,
Object
the executed handler
handler
)

Handle the case when a declared path variable does not match any extracted URI variable.

protected ModelAndView

Returns:

an empty ModelAndView indicating the exception was handled, or null indicating the exception should be handled in handleErrorResponse
handleMissingServletRequestParameter
(MissingServletRequestParameterException
the MissingServletRequestParameterException to be handled
ex
,
HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
,
Object
the executed handler
handler
)

Handle the case when a required parameter is missing.

protected ModelAndView

Returns:

an empty ModelAndView indicating the exception was handled, or null indicating the exception should be handled in handleErrorResponse
handleMissingServletRequestPartException
(MissingServletRequestPartException ex, HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
,
Object
the executed handler
handler
)

Handle the case where an @RequestPart, a MultipartFile, or a jakarta.servlet.http.Part argument is required but is missing.

protected ModelAndView

Returns:

an empty ModelAndView indicating the exception was handled, or null indicating the exception should be handled in handleErrorResponse
handleNoHandlerFoundException
(NoHandlerFoundException
the NoHandlerFoundException to be handled
ex
,
HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
,
Object
the executed handler, or null if none chosen at the time of the exception (for example, if multipart resolution failed)
handler
)

Handle the case where no handler was found during the dispatch.

protected ModelAndView

Returns:

an empty ModelAndView indicating the exception was handled, or null indicating the exception should be handled in handleErrorResponse
handleNoResourceFoundException
(NoResourceFoundException
the NoResourceFoundException to be handled
ex
,
HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
,
Object
the resource handler
handler
)

Handle the case where no static resource was found.

protected ModelAndView

Returns:

an empty ModelAndView indicating the exception was handled, or null indicating the exception should be handled in handleErrorResponse
handleServletRequestBindingException
(ServletRequestBindingException
the exception to be handled
ex
,
HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
,
Object
the executed handler
handler
)

Handle the case when an unrecoverable binding exception occurs - e.g. required header, required cookie.

protected ModelAndView

Returns:

an empty ModelAndView indicating the exception was handled
handleTypeMismatch
(TypeMismatchException
the TypeMismatchException to be handled
ex
,
HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
,
Object
the executed handler
handler
)

Handle the case when a org.springframework.web.bind.WebDataBinder conversion error occurs.

protected void
logException(Exception
the exception that got thrown during handler execution
ex
,
HttpServletRequest
current HTTP request (useful for obtaining metadata)
request
)

Overrides org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.logException.

Log the given exception at warn level, provided that warn logging has been activated through the "warnLogCategory" property.

protected void
sendServerError(Exception ex, HttpServletRequest request, HttpServletResponse response)

Invoked to send a server error.

Inherited from org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver:
addMappedHandlerClassbuildLogMessagegetMappedHandlerClassesgetOrderhasHandlerMappingsprepareResponsepreventCachingresolveExceptionsetMappedHandlerClassessetMappedHandlerPredicatesetMappedHandlerssetOrdersetPreventResponseCachingsetWarnLogCategoryshouldApplyTo