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

Spring Boot 2.7.18与Spring Cloud 2021.0.9兼容性问题咨询

Spring Boot 2.7.18与Spring Cloud 2021.0.9兼容性错误排查与解决

错误原因

问题核心是项目Spring Cloud组件版本不统一:

  • 你在properties中定义了spring-cloud.version=2021.0.9(Jubilee版本,本应适配Spring Boot 2.6.x/2.7.x),但手动给spring-cloud-starter-netflix-eureka-client指定了3.0.4、spring-cloud-starter-openfeign指定了3.0.5——这两个版本属于Spring Cloud 2020.0.x(Ilford),仅适配Spring Boot 2.4.x/2.5.x。
  • 由于未引入Spring Cloud的依赖管理(spring-cloud-dependencies),Maven无法自动对齐组件版本,旧版本Cloud组件与2.7.18的Boot冲突,触发兼容性校验报错。

解决步骤

要保留Spring Boot 2.7.18并使用Spring Cloud 2021.0.9,按以下方式修改POM:

  1. 添加Spring Cloud依赖管理
    加入dependencyManagement块,让Spring Cloud统一管理所有组件版本,避免手动指定版本引发的冲突:
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
  1. 移除手动指定的Spring Cloud组件版本
    删除spring-cloud-starter-netflix-eureka-client和spring-cloud-starter-openfeign中的<version>标签,依赖管理会自动注入2021.0.9对应的正确版本(3.1.9)。

  2. 修复Spring Data Rest版本冲突
    你手动指定的spring-data-rest-hal-browser:3.3.9.RELEASE适配Spring Boot 2.3.x,与2.7.18不兼容,需移除<version>标签,让Spring Boot parent自动管理对应版本(Spring Boot 2.7.18对应Spring Data Rest 3.7.18)。

修改后的完整POM示例

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.18</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.seqnc</groupId>
    <artifactId>subscription-service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>subscription-service</name>
    <description>Subscription service - Chargebee library</description>
    
    <properties>
        <java.version>17</java.version>
        <spring-cloud.version>2021.0.9</spring-cloud.version>
        <spring-doc-version>2.6.0</spring-doc-version>
    </properties>

    <!-- 添加Spring Cloud依赖管理 -->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-rest-hal-browser</artifactId>
            <!-- 移除手动版本,由Spring Boot parent管理 -->
        </dependency>
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
            <version>${spring-doc-version}</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            <!-- 移除手动版本,由Spring Cloud依赖管理注入正确版本 -->
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
            <!-- 移除手动版本,由Spring Cloud依赖管理注入正确版本 -->
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <finalName>subscription-service</finalName>
    </build>

</project>

额外说明

  • 不建议禁用spring.cloud.compatibility-verifier.enabled=false,这会隐藏潜在版本冲突,可能引发运行时异常。
  • Spring Cloud 2021.0.x(Jubilee)从2021.0.3开始确实支持Spring Boot 2.6.x/2.7.x,版本对齐后即可解决兼容性问题。

内容的提问来源于stack exchange,提问作者Dattatreya Kugve

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 18:17:03