SpringBoot custom error page, SpringBoot 404, 500 error prompt page

SpringBoot custom error page, SpringBoot 404, 500 error prompt page

SpringBoot 4xx.html, 5xx.html error prompt page

 

================================

©Copyright Sweet Potato Yao March 27, 2018

http://fanshuyao.iteye.com/

 

1. SpringBoot 404, 500 error prompt page

1. When using the ThymeLeaf template, springBoot will automatically

src/main/resources/templates/error/

Find the error page of 404.htm and 500.html in the folder

The naming rule of the error prompt page is: error code.html, such as 404 is 404.html, 500 is 500.html



 

 

2. If the ThymeLeaf template is not used, SpringBoot will go to the static resource folder to find the error prompt pages of 404.htm and 500.html, named the same as above.

SpringBoot's default static resource files are:

/static

 This is directly generated by the SpringBoot project.

There are also 3 hidden static resource folders:

/resources
/public
/METAINF/resources/

 

 That is, there are 4 default static resource paths in Springboot, which are:

classpath:/METAINF/resources/

classpath:/resources/

classpath:/static/

classpath:/public/

The priority order is: META-INF/resources > resources > static > public

 

You can modify the default mapping** by modifying the spring.mvc.static-path-pattern property in the application.properties file. The configuration is as follows:

 

spring.mvc.static-path-pattern=/**
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/myfile/

 

 二、SpringBoot 4xx.html、5xx.html错误提示页面

错误代码的类型很多,如400、403、404等等,如果按照上面的方法,需要添加很多页面而

SpringBoot提供了通用的命名方式,就是使用4xx.html、5xx.html命名,如:

4xx.html表示能匹配到400、403、404……等错误

5xx.html表示能匹配到500、501、502……等错误

 

如果404.html和4xx.html同时存在时,优先使用最匹配的,即当发生404错误时,优先匹配404.html页面

 

附件见源码:SpringBoot-自定义错误提示.zip

 

=====================错误信息自定义进阶见:================================

SpringBoot自定义错误信息,SpringBoot自定义异常处理类,

SpringBoot异常结果处理适配页面及Ajax请求,

SpringBoot适配Ajax请求

http://fanshuyao.iteye.com/blog/2414865

 

================================

©Copyright 蕃薯耀 2018年3月27日

http://fanshuyao.iteye.com/

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326107867&siteId=291194637