如何覆盖 Spring Boot 依赖项默认版本?

Posted

技术标签:

【中文标题】如何覆盖 Spring Boot 依赖项默认版本?【英文标题】:How to override Spring Boot dependencies default version? 【发布时间】:2017-01-29 12:34:08 【问题描述】:

如何更改 Spring Boot 依赖项的默认版本? 例如 Spring Boot 1.4 使用 Thymeleaf 2.1 版本,但 Thymeleaf 的最新版本是 3.0。那么如何将2.1版本改为3.0呢?

【问题讨论】:

【参考方案1】:

文档describes how to do this。

从问题上的标签来看,您使用的是 Maven。您应该在应用程序的 pom.xml 中添加一个属性来设置 Thymeleaf 版本:

<properties>
    <thymeleaf.version>3.0.1.RELEASE</thymeleaf.version>
</properties>

还有一个sample application 展示了如何将 Thymeleaf 3.0 与可能感兴趣的 Spring Boot 1.4 结合使用。

【讨论】:

【参考方案2】:

Andy 提供的答案仅在您的 POM 继承自 spring-boot-dependencies 时才有效。当通过dependencyManagement 添加spring-boot-dependencies 时,您必须重新定义要覆盖的所有工件。无赖!

这在Andy引用的文档中也有说明(可能是后来添加的)。

【讨论】:

这里是参考docs.spring.io/spring-boot/docs/2.4.5/maven-plugin/reference/…

以上是关于如何覆盖 Spring Boot 依赖项默认版本?的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Spring Boot 中选择性地升级依赖项? (示例案例:Spring Data)

如何使用 spring boot 插件 2.0.x 从一个具有不同依赖项的 gradle 项目生成 2 个 jars

Spring Boot 默认指标从哪来?

如何使用spring boot plugin 2.0.x从一个具有不同依赖项的gradle项目生成2个jar

如何排除依赖项被 Spring Boot 的依赖项管理插件固定?

如何通过依赖项禁用通过 spring.factories 注册的 spring 工厂并保留此 spring-boot 依赖项?