@ConditionalOnWebApplication
@AutoConfigureAfter(value={org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration.class,org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration.class})
public class ErrorsAutoConfiguration
extends Object
WebErrorHandlers filled with
builtin, custom and default fallback WebErrorHandlers.
WebErrorHandlers are those we provided out of the box. It's highly recommended
to use these implementations with most possible priority, as we did in this auto-configuration.
WebErrorHandler implementations. Just implement the
WebErrorHandler interface and register it as Spring Bean. If you're willing to prioritize
your implementations, use the Spring Order annotation
to specify the priority requirements of the bean.
Please Note that your custom handlers would be registered after the built-in ones. If you're
not OK with that, you can always discard this auto-configuration by registering your own
WebErrorHandlers factory bean.
WebErrorHandler in WebErrorHandlers
would be consulted one after another (Depending on their priority). If all of the registered handlers
refuse to handle the exception, then a default fallback WebErrorHandler should handle the exception.
By default, WebErrorHandlers use the LastResortWebErrorHandler as the
default handler. You can replace this handler by providing a WebErrorHandler and register it with
a bean named defaultWebErrorHandler.WebErrorHandler,
WebErrorHandlers,
LastResortWebErrorHandler| Constructor and Description |
|---|
ErrorsAutoConfiguration() |
| Modifier and Type | Method and Description |
|---|---|
org.springframework.boot.web.servlet.error.ErrorAttributes |
errorAttributes(WebErrorHandlers webErrorHandlers,
HttpErrorAttributesAdapter httpErrorAttributesAdapter)
Registers a
ErrorAttributes implementation which would replace the default one provided
by the Spring Boot. |
ErrorsControllerAdvice |
errorsControllerAdvice(WebErrorHandlers webErrorHandlers,
HttpErrorAttributesAdapter httpErrorAttributesAdapter)
Registers a
RestControllerAdvice to catch all
exceptions thrown by the web layer. |
HttpErrorAttributesAdapter |
httpErrorAttributesAdapter()
In the absence of a bean of type
HttpErrorAttributesAdapter, registers the default
implementation of HttpErrorAttributesAdapter as a bean, to adapt our
HttpError to Spring's ErrorAttributes abstraction. |
MissingRequestParametersWebErrorHandler |
missingRequestParametersWebErrorHandler()
Registers a
WebErrorHandler to handle new Servlet exceptions defined in Spring Framework 5.1. |
SpringSecurityWebErrorHandler |
springSecurityWebErrorHandler()
Registers a
WebErrorHandler bean to handle Spring Security specific exceptions when
Spring Security's jar file is present on the classpath. |
javax.validation.Validator |
validator()
Registers a new validator that does not interpolate messages.
|
WebErrorHandlers |
webErrorHandlers(org.springframework.context.MessageSource messageSource,
List<WebErrorHandler> customHandlers,
WebErrorHandler defaultWebErrorHandler,
ExceptionRefiner exceptionRefiner)
Registers a bean of type
WebErrorHandlers (If not provided by the user) filled with a set of
built-in WebErrorHandlers, a set of custom WebErrorHandlers and a default fallback
WebErrorHandler. |
@Bean @ConditionalOnMissingBean public WebErrorHandlers webErrorHandlers(org.springframework.context.MessageSource messageSource, @Autowired(required=false) List<WebErrorHandler> customHandlers, @Qualifier(value="defaultWebErrorHandler") @Autowired(required=false) WebErrorHandler defaultWebErrorHandler, @Autowired(required=false) ExceptionRefiner exceptionRefiner)
WebErrorHandlers (If not provided by the user) filled with a set of
built-in WebErrorHandlers, a set of custom WebErrorHandlers and a default fallback
WebErrorHandler.messageSource - Will be used for error code to error message translation.customHandlers - Optional custom WebErrorHandlers.defaultWebErrorHandler - A default WebErrorHandler to be used as the fallback error handler.exceptionRefiner - To refine exceptions before handling them.WebErrorHandlers.@Bean @ConditionalOnBean(value=WebErrorHandlers.class) public ErrorsControllerAdvice errorsControllerAdvice(WebErrorHandlers webErrorHandlers, HttpErrorAttributesAdapter httpErrorAttributesAdapter)
RestControllerAdvice to catch all
exceptions thrown by the web layer. If there was no WebErrorHandlers in the application
context, then the advice would not be registered.webErrorHandlers - The exception handler.httpErrorAttributesAdapter - To adapt our and Spring Boot's error representations.@Bean(value={"mvcValidator","defaultValidator"})
@ConditionalOnBean(value=WebErrorHandlers.class)
public javax.validation.Validator validator()
@Bean @ConditionalOnBean(value=WebErrorHandlers.class) @ConditionalOnMissingBean(value=HttpErrorAttributesAdapter.class) public HttpErrorAttributesAdapter httpErrorAttributesAdapter()
HttpErrorAttributesAdapter, registers the default
implementation of HttpErrorAttributesAdapter as a bean, to adapt our
HttpError to Spring's ErrorAttributes abstraction.HttpErrorAttributesAdapter.@Bean @ConditionalOnBean(value=WebErrorHandlers.class) public org.springframework.boot.web.servlet.error.ErrorAttributes errorAttributes(WebErrorHandlers webErrorHandlers, HttpErrorAttributesAdapter httpErrorAttributesAdapter)
ErrorAttributes implementation which would replace the default one provided
by the Spring Boot. This ErrorAttributes would be used to adapt Spring Boot's error model
to our customized model.webErrorHandlers - To handle exceptions.httpErrorAttributesAdapter - Adapter between HttpError and
ErrorAttributes.HttpErrorAttributes.@Bean @ConditionalOnBean(value=WebErrorHandlers.class) @ConditionalOnClass(name="org.springframework.security.access.AccessDeniedException") public SpringSecurityWebErrorHandler springSecurityWebErrorHandler()
WebErrorHandler bean to handle Spring Security specific exceptions when
Spring Security's jar file is present on the classpath.@Bean @ConditionalOnBean(value=WebErrorHandlers.class) @ConditionalOnClass(name="org.springframework.web.bind.MissingRequestHeaderException") public MissingRequestParametersWebErrorHandler missingRequestParametersWebErrorHandler()
WebErrorHandler to handle new Servlet exceptions defined in Spring Framework 5.1.
This handler would be registered iff we're using Spring Boot 2.1.0+.Copyright © 2018. All rights reserved.