How I create an error handler (404, 500…) in Spring Boot/MVC

后端 未结 5 1796
终归单人心
终归单人心 2020-12-05 06:06

For some hours I\'m trying to create a custom global error handler in Spring Boot/MVC. I\'ve read a lot of articles and nothing.

That is my error class:

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-05 06:36

    Update for spring boot

    Custom error pages

    If you want to display a custom HTML error page for a given status code, you add a file to an /error folder. Error pages can either be static HTML (i.e. added under any of the static resource folders) or built using templates. The name of the file should be the exact status code or a series mask.

    For example, to map 404 to a static HTML file, your folder structure would look like this

    src/
     +- main/
         +- java/
         |   + 
         +- resources/
             +- public/
                 +- error/
                 |   +- 404.html
                 +- 
    

    Source

提交回复
热议问题