【问题标题】:How to customize Spring webflux error page如何自定义 Spring webflux 错误页面
【发布时间】:2019-03-24 18:05:51
【问题描述】:

当我尝试在 spring initializr 上创建一个演示项目并选择 spring-boot-starter-webflux 时,我无法终生自定义我的错误页面。我尝试将模板放在 /resources/public/error、/resources/templates/error 下(我正在使用 Thymeleaf),定义自定义 ErrorController 无济于事。例如,每次我想抛出 404 页面时,应用程序都会抛出 WhiteLabel 页面。但是当我将依赖项更改为 spring-boot-starter-web 时,它会立即选择我的模板。

是否有其他方式来声明错误页面或者这只是一个错误(当前使用 Spring Boot 2.1.0.RC1,但同样的事情发生在 2.1.0.M4 上)?

我的依赖如下:

    <dependencies>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>de.flapdoodle.embed</groupId>
        <artifactId>de.flapdoodle.embed.mongo</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

【问题讨论】:

    标签: spring-webflux


    【解决方案1】:

    解决了。我不得不将 Spring Boot 版本更改为 2.0.5.RELEASE,因为 2.0.6.RELEASE 表现出相同的行为。

    【讨论】:

    • 这没有解决。这可能是一个错误。您能在 Spring Boot 跟踪器上提出问题吗?
    • 谢谢,我有。 2.1.0刚刚发布,行为还是一样。
    猜你喜欢
    • 2020-12-20
    • 2021-02-26
    • 2014-01-30
    • 2014-11-30
    • 2016-01-17
    • 2018-02-11
    • 1970-01-01
    • 2017-10-03
    • 2021-12-01
    相关资源
    最近更新 更多