Springboot 2.0.2 无法使用 thymeleaf 模板,抛出 404 错误

Sam*_*Sam 3 spring thymeleaf spring-boot

我正在使用 Springboot 1.5.7 作为我的其余 api 应用程序,并且我正在使用 thymeleaf 模板从我的 api 发送电子邮件。但是当我将 spring boot 的版本更新到 2.0.2 时,它会抛出 404 错误,即“解析模板“错误”时出错,模板可能不存在或可能无法被任何配置的模板解析器访问”。

以下是我在 application.yml 中的配置

spring:
  thymeleaf:
    cache: false
    enabled: true
    mode: HTML5
    prefix: /templates/
    suffix: .html   
Run Code Online (Sandbox Code Playgroud)

pom.xml 中的 thymeleaf 版本

 <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-thymeleaf</artifactId>
      <version>2.0.2.RELEASE</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

以下是我正在使用的模板结构,

在此输入图像描述

我的应用程序版本即将发布,我严重陷入这个问题,如果有人可以为我提供解决方法,那么这将是一个很大的帮助。

Has*_*req 5

prefix: /templates/从......中去除application.yml

如果仍然不起作用,请添加thymeleaf-layout-dialect依赖项(请参阅:Thymeleaf 在迁移到 Thymeleaf 3 后停止解析布局模板

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

<dependency>
    <groupId>nz.net.ultraq.thymeleaf</groupId>
    <artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)

仅供参考,我将我的观点放入WEB-INF/webapp/views,所以我正在使用prefix: /WEB-INF/webapp/views/(spring boot war部署到tomcat)