【发布时间】:2017-08-14 07:40:23
【问题描述】:
我的 Spring Boot 应用程序中有以下项目结构,我想在其中使用 Thymeleaf
projectName
-Gradle-Module1(Spring boot module)
-build
-src
-main
-resources
-templates
index.html
build.gradle
-Gradle-Module2
...
build.gradle
...
但是 spring-boot 找不到我的模板目录并显示警告
找不到模板位置:classpath:/templates/(请添加一些模板或检查您的 Thymeleaf 配置)
PS:我使用的是@EnableAutoConfiguration
在我的控制器代码中,我正在执行以下操作:
@Controller
@EnableAutoConfiguration
public class BaseController {
@RequestMapping(value = "/")
public String index() {
return "index.html";
}
}
index.html 文件只打印 hello world。
所以通常它应该在src/resources/templates/(我想是同一个 Gradle 模块的)内部查找,但不知何故它无法找到它。
当我尝试访问 localhost:8080 时出现以下错误
解析模板“index.html”时出错,模板可能不存在或可能无法被任何已配置的模板解析器访问`
我有什么遗漏吗?
任何指针表示赞赏。谢谢。
【问题讨论】:
-
这是一个很好的问题。感谢您的提问!
标签: java spring spring-boot thymeleaf