[英]Custom error page in spring boot
I'm trying to create custom error page in my web-application instead of white-label pages. 我正在尝试在Web应用程序中创建自定义错误页面,而不是白标签页面。 As I know all I need to do in Spring Boot is to add an error.html file under resources/static/templates path, so I did it (I'm using Thymeleaf). 据我所知,我在Spring Boot中需要做的就是在resources / static / templates路径下添加一个error.html文件,所以我做到了(我正在使用Thymeleaf)。 But now instead of white-label pages, it shows me tomcat error pages. 但是现在,它显示的是tomcat错误页面,而不是白标签页面。 I have also tried to add: 我也尝试添加:
server.error.whitelabel.enabled=true
to the properties file, but the result is the same - container error pages. 到属性文件,但结果是相同的-容器错误页面。 What is the right way to do it? 正确的做法是什么?
The simplest way is to add these lines to the web.xml configuration file that redirects all the Tomcat 404 errors to the defined page error.html
: 最简单的方法是将这些行添加到web.xml配置文件中,该文件会将所有Tomcat 404错误重定向到定义的页面error.html
:
<error-page>
<error-code>404</error-code>
<location>/error.html</location>
</error-page>
try this link 试试这个链接
http://www.baeldung.com/custom-error-page-spring-mvc http://www.baeldung.com/custom-error-page-spring-mvc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.