如何在不使用Thymeleaf或其他模板引擎的情况下处理Spring Boot中的Whitelabel 404错误

the*_*ddy 1 java spring reactjs spring-boot

我有一个带有 React JS 客户端的 Spring Boot + Spring Security 应用程序。我想在其中有一个自定义样式的 404 错误页面,而不使用 Thymeleaf。

我的Spring Boot版本是2.0.0.M2

war文件结构是

root-dir
|- WEB-INF
|   |- lib
|   |- classes
|   |   |- static
|   |   |   |- * (react dist)
|   |   |- * (other files)
|- org
|- META-INF
Run Code Online (Sandbox Code Playgroud)

我的 war 文件构建过程如下。

  1. 使用 Gradle npm 插件构建 ReactJS 发行版
  2. Gradle 任务将把发行版复制到staticwar 目录中
  3. 最终建立战争

请帮我解决这个问题。

Vin*_*zak 5

无需禁用白标签页。只需在src/main/resources/public/error目录下添加一个名为404.html的文件即可。

Baeldung.com 指示src/main/resources/public/errors,这不起作用,至少在 SpringBoot 2.1.x 中是这样。使用单一错误,你就会很好。

所有这些工作都不需要项目依赖项中的任何模板引擎。