【问题标题】:Can't add custome error page in thymeleaf无法在 thymeleaf 中添加自定义错误页面
【发布时间】:2020-05-01 05:25:15
【问题描述】:

您好,我正在尝试在 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-boot thymeleaf


    【解决方案1】:

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

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

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

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

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

    【讨论】:

    • 这很奇怪,那一定是配置问题!
    • 解决了,我添加了一行来删除白标签,这是导致问题的原因。我删除了它。
    • 是这个配置吗server.error.whitelabel.enabled=false
    • 如果您解决了,我建议您将解决方案添加到您的问题中,以使遇到相同问题并访问此页面的人受益。
    猜你喜欢
    • 1970-01-01
    • 2015-11-16
    • 2017-10-18
    • 1970-01-01
    • 2018-12-27
    • 1970-01-01
    • 2019-11-28
    • 1970-01-01
    • 2015-05-26
    相关资源
    最近更新 更多