问题|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>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值