环境:IDEA、maven、spring、Thymeleaf
报错页面:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu May 28 17:08:33 CST 2020
There was an unexpected error (type=Internal Server Error, status=500).
Exception parsing document: template=“index1”, line 6 - column 3
查看控制台
提示:
org.xml.sax.SAXParseException: 元素类型 “meta” 必须由匹配的结束标记 “</meta>
” 终止。
这个其实是thymeleaf语法检查的问题,可以选择直接按照提示修改语法,也可以配置文件,直接一劳永逸去掉严格检查。
选择修改语法:
就不写详细过程了,缺啥写啥,按照提示直接加</meta>
和其他的关闭标签就可。
选择配置:
application.yml
新建yml文件在resource目录下
文件中加入以下配置:
spring:
thymeleaf:
mode: LEGACYHTML5 # 不进未关闭标签检查,需配合nekohtml使用
pom.xml
添加neko和thymeleaf版本号:
<dependencies>
<!--我的neko配置, 用于解决thymeleaf报错问题-->
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>${nekohtml.version}</version>
</dependency>
</dependencies>
<!--...-->
<properties>
<!--配置thymeleaf-->
<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.0.5</thymeleaf-layout-dialect.version>
</properties>
刷新maven
如果在idea里面使用,一定记得刷一下maven!!!
如图那个小m图标,快捷键Ctrl+Shift+O
重新运行项目,完成
用maven来build之后,重启一下服务器,应该不会报错了。
参考链接
spring官方配置文档
spring-boot-starter-thymeleaf对没有结束符的HTML5标签解析出错
springboot 使用thymeleaf 模板引擎时报错org.xml.sax.SAXParseException: 元素类型 “link” 必须由匹配的结束标记 “” 终止