springboot2.x 设置404页面

springboot2.x 设置404页面

出现404状态码的时候,我们可以需要显示一个自定义的页面。这篇随便讲简短的介绍如何配置404页面。

首先,添加下面这行代码到你的properties文件里面 关闭 WhiteLabel 错误页面。

WhiteLabel 错误页面。是通用的 Spring Boot 错误页面,当不存在自定义错误页面时显示。

server.error.whitelabel.enabled=false

然后在讲你的404页面放到下面的这样的目录里面

src/
 +- main/
     +- java/
     |   + <source code>
     +- resources/
         +- public/
             +- error/
                 +- 404.html

参考来源:

https://stackoverflow.com/questions/54874290/spring-boot-2-1-error-html-page-not-showing

posted @ 2021-02-09 14:31  Blithe-Chiang  阅读(612)  评论(0编辑  收藏  举报