当前位置: 移动技术网 > IT编程>开发语言>Java > An error happened during template parsing (template: “class path resource [templates/xxx.html]“)

An error happened during template parsing (template: “class path resource [templates/xxx.html]“)

2020年07月27日  | 移动技术网IT编程  | 我要评论
今天由于自己不小心删除了一点东西,当时没有发现,然后就开始了长达几个小时的“抗战”。看问题之前,我先来描述一下我的项目环境:我在使用Spring Boot做一个小型web项目的时候,整合了thymeleaf。项目文件目录如下:事情的起因是这样的:本来页面跳转什么问题都没有,一切正常,突然之间不知道碰到了什么,可能不小心删除了一些东西。也可能是写错了什么,打开页面时出现了如下报错系统后台报错如下:2020-07-24-23-25 [http-nio-8080-exec-8] [org.thyme

今天由于自己不小心删除了一点东西,当时没有发现,然后就开始了长达几个小时的“抗战”。

看问题之前,我先来描述一下我的项目环境:
我在使用Spring Boot做一个小型web项目的时候,整合了thymeleaf。项目文件目录如下:
我的项目文件目录

事情的起因是这样的:本来页面跳转什么问题都没有,一切正常,突然之间不知道碰到了什么,可能不小心删除了一些东西。也可能是写错了什么,打开页面时出现了如下报错
在这里插入图片描述
系统后台报错如下:

2020-07-24-23-25 [http-nio-8080-exec-8] [org.thymeleaf.TemplateEngine] [ERROR] - [THYMELEAF][http-nio-8080-exec-8] Exception processing template "html/textExtraction": An error happened during template parsing (template: "class path resource [templates/html/textExtraction.html]")
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/html/textExtraction.html]")
	at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241)
	at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100)
	at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:666)
	at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098)
	at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072)

看到这个An error happened during template parsing错误的时候,我首先想到的是我的试图解析器配置错了。我的解决思路大改如下:

1、检查pom文件中的thymeleaf依赖。

大概看了一下导入的包,感觉没什么大问题。进行下一步。

<!-- 引入thymeleaf依赖 -->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

2、查看资源配置文件application.properties中thymeleaf的相关配置是否正确。

大概看了一下,感觉没什么大问题。进行下一步。

#thymelea模板配置
##############################################
#
# thymeleaf静态资源配置
#
##############################################
# 默认路径
spring.thymeleaf.prefix=classpath:/templates/
# 后缀
spring.thymeleaf.suffix=.html
# 模板格式
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html

3、查看controller控制器类中是不是有错。

在这里插入图片描述
这我就很奇怪了,到底是哪里的问题呢。难道是我试图解析器有问题?难道没有生效么?
这时候就开始了我的
“抗战”生活,开始借助百度和系统斗智斗勇~
其中的泪水就不说了。

最后,通过检查别的页面都没问题,终于让我意识到,我的这个页面一定出现了什么未知的错误。
在这里插入图片描述
最后改成:

<script th:inline="javascript">

我的问题到此解决~


码字不易,个人微信公众号:"码农想翻身",只不过还没有写任何东西

本文地址:https://blog.csdn.net/feng_xiaolin/article/details/107571657

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网