springboot 2.0 Thymeleaf 找不到模板错误template might not exist or might not be accessible

网上的 项目原来是 springboot 1.5X项目,用springboot2.0X 搭建报错:

org.thymeleaf.exceptions.TemplateInputException: Error resolving template [login], template might not exist or might not be accessible by any of the configured Template Resolvers

各种修改:

以为是配置文件,或者thymeleaf 版本问题导致的

  1、配置文件

       

#spring.thymeleaf.prefix=classpath:/templates/  此配置经验证 可以不配 默认会找到这个包,前提是包名必须是 templates
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.servlet.content-type=text/html 
spring.thymeleaf.cache=false

2、pom 文件

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-thymeleaf</artifactId>
   <!--<version>3.0.9.RELEASE</version>-->  本身内置版本为<version>2.1.5.RELEASE</version>
</dependency>

最后发现问题 为被坑了:

<build>

   <resources>
      <resource>
         <directory>src/main/java</directory>
         <includes>
            <include>**/*.yml</include>
            <include>**/*.properties</include>
            <include>**/*.xml</include>
         </includes>
         <filtering>false</filtering>
      </resource>

就是下面这段 把html 过滤掉了 去掉 添加 <include>**/*.html</include> 都可以
   <resource>
         <directory>src/main/resources</directory>
         <includes>
            <include>**/*.yml</include>
            <include>**/*.properties</include>
            <include>**/*.xml</include>
         </includes>
         <filtering>false</filtering>
      </resource>
   </resources>
   <plugins>
      <plugin>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
   </plugins>
</build>

版权声明:本文为yechangfeng47原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。