spring-boot - 无法在 thymeleaf 中添加客户错误页面
问题描述
嗨,我正在尝试在 thymeleaf 项目中通过在模板中添加 404.html 页面来添加自定义错误页面。
但是当我输入 localhost:8080/RandomUrl-doesn't-that-exist 我有标准错误 404 消息。
我的配置:
#for Spring Boot 2.0
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
Solution : don't remove whitelabel message in applications.properties
解决方案
error
要在 Thymeleaf 中创建通用页面,只需将error.html
文件添加到模板文件夹中
像这样 -->src/main/resources/templates/error.html
但如果你想处理特定的错误,例如404
,
创建errors
页面,然后404.html
在其中创建页面。
像这样 -->src/main/resources/templates/error/404.html
推荐阅读
- node.js - Node.js HTTP 服务器中的参数
- github - 如何创建从我的 github README.md 到存储库中一些静态 html 的链接?
- flutter - Flutter using Draggable & DragTarget:在拖动时更新“childWhenDragging”位置,因为候选者在拖动目标上拖动
- pug - 如何在 PUG 中使用变量和 if else 条件
- ios - Activity Indicator appeared in Wrong View Hierarchy
- android - prevent on back pressed to work after using navigation to navigate from one fragment to the other
- python - Improve performance of running large files
- flutter - 在颤动中从应用程序栏调用覆盖小部件
- asp.net-mvc - 如何在 Quill JS 上保留空白,同时保持 Microsoft Word 的复制/粘贴格式?
- c++ - 模板的继承参数设置