spring - Springboot 2.0.2 无法使用 thymeleaf 模板,抛出 404 错误
问题描述
我将 Springboot 1.5.7 用于我的 rest api 应用程序,并且我正在使用 thymeleaf 模板从我的 api 发送电子邮件。但是,当我将 Spring Boot 的版本更新到 2.0.2 时,它会抛出 404 错误,即“解析模板时出错”,模板可能不存在,或者任何配置的模板解析器都可能无法访问”。
下面是我在 application.yml 中的配置
spring:
thymeleaf:
cache: false
enabled: true
mode: HTML5
prefix: /templates/
suffix: .html
pom.xml 中的百里香叶版本
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
下面是我正在使用的模板结构,
我的应用程序发布已经很接近了,我严重地陷入了这个问题,如果有人可以为我提供解决方法,那将是一个很大的帮助。
解决方案
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>
仅供参考,我把我的观点放在了WEB-INF/webapp/views
,所以我正在使用prefix: /WEB-INF/webapp/views/
(spring boot war deploy to tomcat)
推荐阅读
- r - 带有空表的闪亮 R renderDataTable
- python - 我在 Heroku Git 上托管了一个 discord.py 机器人,即使我在网站上打开了它,它也不会在 discord 服务器上上线
- sql - PostgreSQL查询说明
- node.js - How can I let my discord bot replies when I say Hi
- reactjs - 如何通过单击反应中的图像来查看模态??(instagram克隆编码)
- tinymce - pub/static 中缺少 Magento 2 tinymce
- flutter - ListTile 不会在每次添加时更新时间
- ruby-on-rails - Rails ajax 创建新记录
- javascript - 我需要您调整图像大小并将其保存在特定路径中,可以吗?(锋利的)
- go - GRPC 未设置某些标头