Spring Boot application enables a global exception handler, to handle exceptions gracefully. Supports handling exceptions occurred in filters, controllers, and event listeners.
- Import dependencies
<dependency>
<groupId>com.yookue.springstarter</groupId>
<artifactId>exception-handler-spring-boot-starter</artifactId>
<version>LATEST</version>
</dependency>
By default, this starter will auto take effect, you can turn it off by
spring.exception-handler.enabled = false
- Configure Spring Boot
application.yml
with prefixspring.exception-handler
(Optional)
spring:
exception-handler:
exception-filter:
filter-paths:
- '/**'
exclude-paths:
- '/foo/**'
- '/bar/**'
exception-resolver:
invokable-interceptors:
- com.foo.bar
-
This starter supports the most popular template engines, including:
- Thymeleaf
- FreeMarker
- Groovy
- Mustache
- JSP
-
Optional feature: If you're using a template engine in your application, you may activate a simple error controller by
@EnableSimpleErrorController
annotation, which extends fromBasicErrorController
and handles both HTML requests and REST requests.
You can also customize the error data generated by this error controller, by the way of defining a bean which implements the
ErrorControllerCustomizer
facade.
You can handle the event named
ServletExceptionHandledEvent
to process your own logic, such as logging and so on.
- jdk 17+
This project is under the Apache License 2.0
See the NOTICE.txt
file for required notices and attributions.
You like this package? Then donate to Yookue to support the development.
- Yookue: https://yookue.com