首页 > 解决方案 > 无法在 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

标签: spring-bootthymeleaf

解决方案


error要在 Thymeleaf 中创建通用页面,只需将error.html文件添加到模板文件夹中

像这样 -->src/main/resources/templates/error.html

但如果你想处理特定的错误,例如404

创建errors页面,然后404.html在其中创建页面。

像这样 -->src/main/resources/templates/error/404.html


推荐阅读