SpringBoot自定义错误页面,SpringBoot 404、500错误提示页面
SpringBoot自定义错误页面,SpringBoot 404、500错误提示页面
SpringBoot 4xx.html、5xx.html错误提示页面
================================
©Copyright 蕃薯耀 2018年3月29日
http://www.cnblogs.com/fanshuyao/
附件&源码下载见:http://fanshuyao.iteye.com/blog/2414828
一、SpringBoot 404、500错误提示页面
1、在使用ThymeLeaf模板时,springBoot会自动到
- src/main/resources/templates/error/
文件夹下寻找404.htm、500.html的错误提示页面
错误提示页面的命名规则就是:错误码.html,如404是404.html,500是500.html
2、如果没有使用ThymeLeaf模板时,SpringBoot会到静态资源文件夹寻找404.htm、500.html的错误提示页面,命名同上。
SpringBoot默认的静态资源文件有:
- /static
这个是生成SpringBoot项目直接有的。
还有3个隐藏的静态资源文件夹:
- /resources
- /public
- /METAINF/resources/
即Springboot中默认的静态资源路径有4个,分别是:
classpath:/METAINF/resources/
,
classpath:/resources/
,
classpath:/static/
,
classpath:/public/
优先级顺序为:META-INF/resources > resources > static > public
可以通过修改application.properties文件中的spring.mvc.static-path-pattern属性来修改默认的映射**,配置如下:
- 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页面
================================
©Copyright 蕃薯耀 2018年3月29日
http://www.cnblogs.com/fanshuyao/
相关文章
- SpringBoot-MongoDB 索引冲突分析及解决
- SpringBoot ( 七 ) :springboot + mybatis 多数据源最简解决方案
- Springboot dubbo @Service @Transactional 无法提供服务或者无法提供事务的解决办法
- springboot 在tomcat中启动两次
- 配置和修改springboot默认国际化文件
- SpringBoot配置属性之DataSource
- 【SpringBoot笔记07】SpringBoot框架集成FastJson处理数据
- 【项目实战】基于前后端分离架构实现多附件同时上传SpringBoot后端
- 【异常】SpringBoot提示错误:Failed to convert from type [java.lang.String] to type [java.util.Date] for value
- SpringBoot到底是什么?
- 补习系列(3)-springboot中的几种scope
- SpringBoot 2 要不要升级
- SpringBoot瘦身打包部署
- SpringBoot踩坑记录 Invalid bound statement (not found)引发的一些列问题
- springboot 配置多个请求服务代理
- Java:SpringBoot启动时打印当前端口
- Springboot的监控Springboot Actuator
- SpringBoot学习笔记(6) SpringBoot数据缓存Cache [Guava和Redis实现]
- SpringBoot配置logback
- SpringBoot实例②springboot+jdbcTemplate小例子实现增删查改
- springboot使用jxls导出excel___(万能通用模板)--- SpringBoot导入、导出Excel文件___SpringBoot整合EasyExcel模板导出Excel
- 关于springboot项目的一下常见的错误及解决办法