0、报如下错误:
xyAdmin- 2025-02-10 20:38:22 [http-nio-443-exec-1] ERROR org.thymeleaf.TemplateEngine - [THYMELEAF][http-nio-443-exec-1] Exception processing template "1webSitePages/defaultPages/websocketTest.html": Error resolving template [1webSitePages/defaultPages/websocketTest.html], template might not exist or might not be accessible by any of the configured Template Resolvers
org.thymeleaf.exceptions.TemplateInputException: Error resolving template [1webSitePages/defaultPages/websocketTest.html], template might not exist or might not be accessible by any of the configured Template Resolvers
at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:869)
at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:607)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072)
at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:366)
at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:190)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1406)
1、引入依赖,引入如下依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2、配置文件如下,以下是windows的配置,如果是Linux系统,那prefix的直接是路径/home/xyAdmin/thymeleafTemplate/
spring:
thymeleaf:
cache: false
prefix: file:/D:/home/xyAdmin/thymeleafTemplate/
suffix: .html
encoding: utf-8
mode: HTML
泣血要记住的内容:刚开始我的地址是配置到jar包中,直接可以访问。但是由于需求变动,需要把模板放到jar外面,好可以直接替换模板。就按照网上说的例子一样,配置了spring.thymeleaf.prefix的路径,其实这样就直接可以用了。但是我应该是脑袋被撞了,没有想清楚。还专门弄了个@Vaule把这个参数放到代码里面读取出来,然后进行地址拼接。导致一直在报标题上面的错误。这么傻的问题,还被困扰了几个小时,一直在纠结为什么不行,真的是脑壳被夹了。