问题|Spring Boot中配置thymeleaf出错 @Spring Boot

Library '...'has broken path

问题描述

背景:

  • 工具: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-成功:

参考:https://blog.csdn.net/t_p_f/article/details/109383498

  • 猜测: 版本问题? 修改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版本冲突问题,可选择:

  1. 修改 Spring Boot :降低spring-boot-starter-parent父级依赖版本
  2. 修改 thymeleaf :<thymeleaf.version>改为<thymeleaf-spring5.version>

全部评论

相关推荐

02-08 20:56
已编辑
南京工业大学 Java
在等offer的比尔很洒脱:我也是在实习,项目先不说,感觉有点点小熟悉,但是我有点疑问,这第一个实习,公司真的让实习生去部署搭建和引入mq之类的吗,是不是有点过于信任了,我实习过的两个公司都是人家正式早搭好了,根本摸不到部署搭建的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务