问题|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-19 21:34
门头沟学院 Java
暴风雨来了:缩成一页,如果找工作的话,最好是要有实习经历,简历也需要改一改,可以私我帮你改一改包装一段实习经历,或者自己在网上找一找冷门的项目,自己包装一下。没有实习经历肯定是不行的。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务