You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Cloud 2020.0.6中无法覆盖Spring Boot版本的问题

Spring Cloud 2020.0.6 升级Spring Boot版本到2.5.x的解决办法

你遇到的问题是:用spring-cloud-starter-parent 2020.0.6作为父依赖,虽然在dependencyManagement里引入了spring-boot-dependencies 2.5.15,但Maven还是拉取了父pom默认的Spring Boot 2.4.13版本。

这是因为Maven dependencyManagement的优先级规则:父pom中定义的依赖版本,优先级高于子pom里通过<scope>import</scope>引入的依赖版本。spring-cloud-starter-parent本身已经在它的dependencyManagement里固定了Spring Boot的版本,所以你直接import spring-boot-dependencies不会生效。

下面给两种可行的解决方式:

方式一:切换父pom为Spring Boot官方父依赖(推荐)

放弃用spring-cloud-starter-parent做父pom,改用spring-boot-starter-parent,然后在dependencyManagement中引入spring-cloud-dependencies来管理Spring Cloud版本。这样能完全掌控Spring Boot的版本,配置示例如下:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.15</version>
</parent>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>2020.0.6</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

方式二:覆盖Spring Cloud父pom的版本属性

如果一定要保留spring-cloud-starter-parent作为父pom,只需要在你的pom里显式设置spring-boot.version属性,覆盖父pom的默认值即可:

<parent>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-parent</artifactId>
    <version>2020.0.6</version>
</parent>

<!-- 显式设置Spring Boot版本属性 -->
<properties>
    <spring-boot.version>2.5.15</spring-boot.version>
</properties>

<!-- 不需要再单独import spring-boot-dependencies -->
<dependencyManagement>
    <!-- 其他依赖管理配置 -->
</dependencyManagement>

这样配置后,Maven就会拉取你指定的Spring Boot 2.5.15版本,同时保持Spring Cloud 2020.0.6的依赖兼容性。

内容的提问来源于stack exchange,提问作者Matt Esen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 03:40:00