thymeleaf 如何找到模板位置?

问题描述 投票:0回答:2

当我启动 Spring Boot 应用程序时,我收到警告,如下所示:

2023-02-16T13:26:47.508-05:00 WARN 23919
--- [ restartedMain] DefaultTemplateResolverConfiguration
Cannot find template location: classpath:/templates/ (please add some templates, check your Thymeleaf configuration, or set spring.thymeleaf.check-template-location=false)

但我的 application.properties 如下:

spring.thymeleaf.prefix=classpath:/templates/

一切似乎都很正常,但我不断收到该错误

我的资源目录如下: enter image description here

有人知道发生什么事吗?我寻找的答案不适合我的奇怪情况。

spring thymeleaf
2个回答
0
投票

首先

src/main/resources/templates
是 Thymeleaf 模板的 默认目录,所以我想你需要删除属性
spring.thymeleaf.prefix=classpath:/templates/
让 Spring 使用默认目录。


0
投票

我在 Junit5 测试中遇到了同样的问题,不得不将我的文件推送到我的文件

src/test/resources/templates
,它解决了问题。我的配置看起来是一样的,但后来我改变了使用:

templateResolver.setPrefix(templatesDirectory); // Set the folder where your templates are located
© www.soinside.com 2019 - 2024. All rights reserved.