我正在开发一个使用 thymeleaf 作为模板引擎的 spring boot web 应用程序。
当我在我的 html 模板中未关闭标签(如 meta、link、br、hr 或输入标签)时,thymeleaf 在嵌入式 spring boot tomcat(运行 jar 文件)上运行时不会提示。
但是当我将应用程序部署到外部独立 tomcat(构建 war 工件)时,由于那些未关闭的标签,我得到了 thymeleaf 解析异常。
我还注意到我确实需要 thymeleaf-layout-dialect 依赖项
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
<version>2.1.2</version>
</dependency>
在使用嵌入式 tomcat 时编译,但在部署到外部独立 tomcat 时编译和运行正常。
为什么会这样?我该如何修复它,使其在嵌入式 tomcat 和任何独立的 tomcat 安装上都相同?
最佳答案
我已经解决了由于使用 Neko HTML 的未闭合标签而抛出异常的问题,但我仍然没有发现为什么这些异常仅在 spring boot 在外部 tomcat 上运行时抛出,而不是在使用嵌入式 tomcat 运行时抛出 Tomcat 。
这是我所做的:
将属性“spring.thymeleaf.mode”设置为“LEGACYHTML5”。
spring.thymeleaf.mode=LEGACYHTML5
然后在 pom.xml 中,添加依赖项:
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
关于java - 仅在外部 Tomcat 上运行时出现 Spring Boot Thymeleaf 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48686277/