我正在使用Springboot 1.5.7进行我的其他api应用程序,我使用百万美元模板从我的api发送电子邮件。但是,当我将spring boot的版本更新为2.0.2时,它抛出了404错误,即“Error resolving template”错误“,模板可能不存在,或者可能无法通过任何已配置的模板解析器访问”。
以下是我在application.yml中的配置
spring:
thymeleaf:
cache: false
enabled: true
mode: HTML5
prefix: /templates/
suffix: .html
pom.xml中的thymeleaf版本
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
以下是我正在使用的模板结构
我的应用程序版本非常接近,我很难解决这个问题,如果有人能为我提供解决方法,那么这将是一个很大的帮助。
答案 0 :(得分:4)
如2.0迁移指南中所述。
Thymeleaf首发包括百里香 - 布局 - 方言依赖 先前。由于Thymeleaf 3.0现在提供native way to implement layouts, 我们删除了强制性依赖关系并将此选择留给您。 如果您的应用程序依赖于布局 - 方言项目,请 将其显式添加为依赖项。
添加以下依赖项应该可以正常工作
<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>
消息来源:https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide#template-engines
答案 1 :(得分:2)
从prefix: /templates/
application.yml
如果仍然无效,请添加thymeleaf-layout-dialect
依赖项(请参阅:Thymeleaf stopped resolving layout templates after migrating to 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>
仅供参考,我将我的观点放在WEB-INF/webapp/views
中,因此我使用prefix: /WEB-INF/webapp/views/
(春季启动战部署到tomcat)