Skip to content

yookue/exception-handler-spring-boot-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Exception Handler Spring Boot Starter

Spring Boot application enables a global exception handler, to handle exceptions gracefully. Supports handling exceptions occurred in filters, controllers, and event listeners.

Quickstart

  • 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 prefix spring.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 from BasicErrorController 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.

Document

Requirement

  • jdk 17+

License

This project is under the Apache License 2.0

See the NOTICE.txt file for required notices and attributions.

Donation

You like this package? Then donate to Yookue to support the development.

Website