使用IDEA 导入Thymeleaf 报错“template might not exist or might not be accessible”

错误名称:template might not exist or might not be accessible by any of the configured Template Resolvers

以下有几个错误点,耽误了2个多小时没排查出来,请仔细对照分析:

1. pom.xml 导入是否正确?

使用IDEA 导入Thymeleaf 报错“template might not exist or might not be accessible”

检查:在External Libraries ->Maven:org.thymeleaf 查看版本

使用IDEA 导入Thymeleaf 报错“template might not exist or might not be accessible”

使用IDEA 导入Thymeleaf 报错“template might not exist or might not be accessible”

若版本是3.0以上继续第二步。

2. 直接检查Target文件是否生成了Templates

使用IDEA 导入Thymeleaf 报错“template might not exist or might not be accessible”

若没有生成,则直接在pom.xml 中增加:

 

 

使用IDEA 导入Thymeleaf 报错“template might not exist or might not be accessible”

 

完整格式长这样:

<!--Maven资源过滤配置-->
<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
                <include>**/*.html</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>

我就是卡在这里了,没有增加html的导出设置,<includes>下只有properties,xml 。 

若非导包的问题,以下是其他排错方案:

方案一:检查 模板名称:index与Controller内return 的名称是否一致(注意return不要加“/”,即return "index" 而非 return "/index")

使用IDEA 导入Thymeleaf 报错“template might not exist or might not be accessible”

使用IDEA 导入Thymeleaf 报错“template might not exist or might not be accessible”

检查方案二: Controller控制器 使用 @Controller注解,而不用 @RestController;

补充:@Controller和@RestController的区别?

https://blog.****.net/lhq186/article/details/87894440