@ExceptionHandler method that handles all Spring MVC
raised exceptions by returning a ResponseEntity with RFC 7807
formatted error details in the body.
Convenient as a base class of an @ControllerAdvice
for global exception handling in an application. Subclasses can override
individual methods that handle a specific exception, override
handleExceptionInternal to override common handling of all exceptions,
or override createResponseEntity to intercept the final step of creating
the ResponseEntity from the selected HTTP status code, headers, and body.
| Modifier and Type | Field and Description |
|---|---|
| protected final Log | logger
Common logger for use in subclasses. |
| private MessageSource | |
| 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
Specific logger to use when no mapped handler is found for a request. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected ProblemDetail | Returns: the createdProblemDetail instancethe exception being handled ex, HttpStatusCode the status to associate with the exception status, String default value for the "detail" field defaultDetail, String the code to use to look up the "detail" field
through a detailMessageCode, Object[] MessageSource; if null then
ErrorResponse#getDefaultDetailMessageCode(Class, String) is used
to determine the default message code to usethe arguments to go with the detailMessageCode detailMessageArguments, WebRequest the current request request)Convenience method to create a |
| protected ResponseEntity | Returns: theResponseEntity instance to usethe body to use for the response body, HttpHeaders the headers to use for the response headers, HttpStatusCode the status code to use for the response statusCode, WebRequest the current request request)Create the |
| protected MessageSource | |
| protected ResponseEntity | Returns: aResponseEntity for the response to use, possibly
null when the response is already committedthe exception to handle ex, HttpHeaders the headers to use for the response headers, HttpStatusCode the status code to use for the response status, WebRequest the current request request)Customize the handling of |
| protected ResponseEntity | Returns: aResponseEntity for the response to use, possibly
null when the response is already committedthe exception to handle ex, HttpHeaders the headers to use for the response headers, HttpStatusCode the status code to use for the response status, WebRequest the current request request)
Deprecated
for removal since 6.0. as of 6.0 since
org.
now raises the MethodArgumentNotValidException subclass instead.
Customize the handling of |
| protected ResponseEntity | Returns: aResponseEntity for the response to use, possibly
null when the response is already committedthe exception to handle ex, HttpHeaders the headers to use for the response headers, HttpStatusCode the status code to use for the response status, WebRequest the current request request)Customize the handling of |
| protected ResponseEntity | Returns: aResponseEntity for the response to use, possibly
null when the response is already committedthe exception to handle ex, HttpHeaders the headers to use for the response headers, HttpStatusCode the status code to use for the response status, WebRequest the current request request)Customize the handling of any |
| public final ResponseEntity | handleException(Exception
the exception to handle ex, WebRequest the current request request)Handle all exceptions raised within Spring MVC handling of the request. |
| protected ResponseEntity | Returns: aResponseEntity for the response to use, possibly
null when the response is already committedthe exception to handle ex, Object the body to use for the response body, HttpHeaders the headers to use for the response headers, HttpStatusCode the status code to use for the response statusCode, WebRequest the current request request)Internal handler method that all others in this class delegate to, for
common handling, and for the creation of a |
| protected ResponseEntity | Returns: aResponseEntity for the response to use, possibly
null when the response is already committedthe exception to handle ex, HttpHeaders the headers to be written to the response headers, HttpStatusCode the selected response status status, WebRequest the current request request)Customize the handling of |
| protected ResponseEntity | Returns: aResponseEntity for the response to use, possibly
null when the response is already committedthe exception to handle ex, HttpHeaders the headers to use for the response headers, HttpStatusCode the status code to use for the response status, WebRequest the current request request)Customize the handling of |
| protected ResponseEntity | Returns: aResponseEntity for the response to use, possibly
null when the response is already committedthe exception to handle ex, HttpHeaders the headers to use for the response headers, HttpStatusCode the status code to use for the response status, WebRequest the current request request)Customize the handling of |
| protected ResponseEntity | Returns: aResponseEntity for the response to use, possibly
null when the response is already committedthe exception to handle ex, HttpHeaders the headers to use for the response headers, HttpStatusCode the status code to use for the response status, WebRequest the current request request)Customize the handling of |
| protected ResponseEntity | Returns: aResponseEntity for the response to use, possibly
null when the response is already committedthe exception to handle ex, HttpHeaders the headers to use for the response headers, HttpStatusCode the status code to use for the response status, WebRequest the current request request)Customize the handling of |
| protected ResponseEntity | Returns: aResponseEntity for the response to use, possibly
null when the response is already committedthe exception to handle ex, HttpHeaders the headers to use for the response headers, HttpStatusCode the status code to use for the response status, WebRequest the current request request)Customize the handling of |
| protected ResponseEntity | Returns: aResponseEntity for the response to use, possibly
null when the response is already committedthe exception to handle ex, HttpHeaders the headers to use for the response headers, HttpStatusCode the status code to use for the response status, WebRequest the current request request)Customize the handling of any |
| protected ResponseEntity | Returns: aResponseEntity for the response to use, possibly
null when the response is already committedthe exception to handle ex, HttpHeaders the headers to be written to the response headers, HttpStatusCode the selected response status status, WebRequest the current request request)Customize the handling of |
| protected ResponseEntity | Returns: aResponseEntity for the response to use, possibly
null when the response is already committedthe exception to handle ex, HttpHeaders the headers to use for the response headers, HttpStatus the status code to use for the response status, WebRequest the current request request)Customize the handling of |
| protected ResponseEntity | Returns: aResponseEntity for the response to use, possibly
null when the response is already committedthe exception to handle ex, HttpHeaders the headers to use for the response headers, HttpStatusCode the status code to use for the response status, WebRequest the current request request)Customize the handling of |
| protected ResponseEntity | Returns: aResponseEntity for the response to use, possibly
null when the response is already committedthe exception to handle ex, HttpHeaders the headers to use for the response headers, HttpStatusCode the status code to use for the response status, WebRequest the current request request)Customize the handling of |
| protected ResponseEntity | Returns: aResponseEntity for the response to use, possibly
null when the response is already committedthe exception to handle ex, HttpHeaders the headers to use for the response headers, HttpStatusCode the status code to use for the response status, WebRequest the current request request)Customize the handling of |
| protected ResponseEntity | Returns: aResponseEntity for the response to use, possibly
null when the response is already committedthe exception to handle ex, HttpHeaders the headers to use for the response headers, HttpStatusCode the status code to use for the response status, WebRequest the current request request)Customize the handling of |
| protected ResponseEntity | Returns: aResponseEntity for the response to use, possibly
null when the response is already committedthe exception to handle ex, HttpHeaders the headers to use for the response headers, HttpStatusCode the status code to use for the response status, WebRequest the current request request)Customize the handling of |
| protected ResponseEntity | Returns: aResponseEntity for the response to use, possibly
null when the response is already committedthe exception to handle ex, HttpHeaders the headers to use for the response headers, HttpStatusCode the status code to use for the response status, WebRequest the current request request)Customize the handling of |
| protected ResponseEntity | Returns: aResponseEntity for the response to use, possibly
null when the response is already committedthe exception to handle ex, HttpHeaders the headers to use for the response headers, HttpStatusCode the status code to use for the response status, WebRequest the current request request)Customize the handling of |
| public void | setMessageSource(MessageSource
message source to be used by this object messageSource)Implements org. Set the Invoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method. |