项目的pom.xml资源过滤配置如下
<resources> <resource> <directory>src/main/resources</directory> <!-- src/main/resources下的指定资源放行 --> <includes> <include>**/*.properties</include> <include>**/*.yml</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> </resources>
spring boot + thymeleaf今天在启动时提示
WARN:Cannot find template location: classpath:/templates/ (please add some templates or check your Thymel]
然后运行页面报错
Error resolving template "pages", template might not exist or might not be accessible by any of the configured Template Resolvers
解决方法:
在application.propertoes或yml配置文件中添加,
spring.freemarker.checkTemplateLocation=false
spring: freemarker: checkTemplateLocation: false
这个有点想不明白,明显都提示模板没找到了还忽略提示,有点奇葩
改application.propertoes,加注释,各种方法都没问题,最后就是页面渲染不出来。
归根结底,还是因为模板没找,这时才想起pom.xml中的资源过滤,把.html的文件类型给过滤掉了。加上就好了。
<resources> <resource> <directory>src/main/resources</directory> <!-- src/main/resources下的指定资源放行 --> <includes> <include>**/*.properties</include> <include>**/*.yml</include> <include>**/*.xml</include> <include>**/*.html</include> </includes> <filtering>false</filtering> </resource> </resources>