Spring Boot启动报Thymeleaf模板位置未找到警告求助
解决Spring Boot启动时Thymeleaf模板位置警告问题
这个警告的核心原因是:你的项目引入了Thymeleaf依赖,但Thymeleaf默认要求的模板存放目录classpath:/templates/不存在,或者目录下没有任何模板文件,启动时会触发路径检查警告。
以下是三种针对性解决方案:
方案一:无需Thymeleaf时直接移除依赖
若你的项目是纯API接口服务,不需要前端模板渲染功能,直接移除项目依赖中的Thymeleaf Starter:
Maven项目(修改pom.xml):<!-- 移除该依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>Gradle项目(修改
build.gradle):// 移除该依赖 implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'方案二:需要Thymeleaf时创建模板目录并添加文件
在项目的src/main/resources目录下直接创建templates文件夹,然后在该文件夹中添加至少一个Thymeleaf模板文件(比如index.html),Thymeleaf启动时会自动识别并加载。方案三:关闭模板位置检查(仅建议测试环境使用)
在你的application.properties中添加以下配置,禁用Thymeleaf的模板路径检查:spring.thymeleaf.check-template-location=false
若之前尝试过类似方案无效,请确认:
- Thymeleaf依赖是否正确引入且无冲突
templates目录是否为src/main/resources的直接子目录(不能嵌套在其他文件夹内)
内容的提问来源于stack exchange,提问作者Nimasha Madhushani
相关产品推荐
相关产品推荐

