问题|Spring Boot中配置thymeleaf出错 @Spring Boot
问题描述
背景:
- 工具:IntelliJ IDEA工具
- 背景:在Spring Boot项目的pom.xml中配置thymeleaf,pom文件中并未报错
- 错误:但打开File → Project Structrue → Modules的Dependencies中,发现一个jar包显示broken path:
Library 'Maven: org.thymeleafthymeleaf-spring5:3.0.2.RELEASE’has broken path.
具体:
解决历程
尝试1-失败:
- 猜测:
maven下载的jar包文件损坏?
- 操作:1. 删除maven的下载目录把spring-boot-starter-thymeleaf目录;2. 重新导入 reimport maven
- 结果:问题依旧存在
尝试2-成功:
- 猜测:
版本问题?
降低Spring Boot版本
- 操作:1. 修改spring-boot-starter-parent父级依赖版本;2. 导入 maven import
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<!--2.4.1版本降低版本为:1.5.7.RELEASE--> <version>1.5.7.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<!--使用thymeleaf3--> <thymeleaf.version>3.0.2.RELEASE</thymeleaf.version> <thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version>
</properties>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
- 结果:成功
尝试3-成功:
- 猜测:
版本问题?
修改thymeleaf配置
- 操作:修改properties中的内容
<thymeleaf-spring5.version>3.0.9.RELEASE</thymeleaf-spring5.version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<!--版本依旧为2.4.1--> <version>2.4.1</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<!--thymeleaf.version修改为springboot-thymeleaf.version--> <springboot-thymeleaf.version>3.0.9.RELEASE</springboot-thymeleaf.version> <thymeleaf-layout-dialect.version>2.2.2</thymeleaf-layout-dialect.version>
</properties>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
- 结果:成功
思路总结
Spring Boot与thymeleaf版本冲突问题,可选择:
- 修改 Spring Boot :降低spring-boot-starter-parent父级依赖版本
- 修改 thymeleaf :<thymeleaf.version>改为<thymeleaf-spring5.version>