将 Spring Cloud 版本从 Edgware 升级到 Hoxton

Posted

技术标签:

【中文标题】将 Spring Cloud 版本从 Edgware 升级到 Hoxton【英文标题】:Upgrading spring cloud version from Edgware to Hoxton 【发布时间】:2021-02-23 00:44:16 【问题描述】:

我正在将spring boot版本从1.5.9升级到2.3.5,spring cloud版本从Edgware.SR2升级到Hoxton.SR6

POM 包括spring-cloud-stream-schemaspring-cloud-starter-eurekaspring-cloud-sleuth-stream,如下所示,当它与Edgware 一起运行时。

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-stream-schema</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-sleuth-stream</artifactId>
    </dependency>

升级后,maven build 报如下错误。

[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] 'dependencies.dependency.version' for org.springframework.cloud:spring-cloud-stream-schema:jar is missing. @ line 89, column 15
[ERROR] 'dependencies.dependency.version' for org.springframework.cloud:spring-cloud-starter-eureka:jar is missing. @ line 97, column 15
[ERROR] 'dependencies.dependency.version' for org.springframework.cloud:spring-cloud-sleuth-stream:jar is missing. @ line 109, column 15

看起来这 3 个 jar 被移出或与 Hoxton.SR6 中的其他 jar 合并。

更新后的依赖项是什么?

【问题讨论】:

spring.io/blog/2018/06/19/… 您是否通过spring-cloud-dependencies BOM 导入您的依赖项(版本)? @DirkDeyne 没有。 spring-boot-starter-parent 【参考方案1】:

Spring Boot 2.x 版现在不支持这些依赖项。

pom.xml 中添加这些更新的依赖项:

       <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
        <dependency>
         <groupId>org.springframework.cloud</groupId>
         <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-sleuth</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream</artifactId>
        </dependency>

完整示例 pom.xml

<?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.3.5.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.so</groupId>
    <artifactId>test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>test</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>11</java.version>
        <spring-cloud.version>Hoxton.SR9</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
        <dependency>
         <groupId>org.springframework.cloud</groupId>
         <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-sleuth</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream</artifactId>
        </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-stream</artifactId>
            <scope>test</scope>
            <classifier>test-binder</classifier>
            <type>test-jar</type>
        </dependency>
    </dependencies>

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

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

</project>

注意:将云版本改为Horton.SR9

【讨论】:

【参考方案2】:
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-schema-registry-client</artifactId>
    <version>1.0.9.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>

【讨论】:

import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.log.Slf4jSpanLogger; 如何满足这两个导入?将spring-cloud-sleuth-stream 更改为spring-cloud-starter-sleuth 不满足依赖...【参考方案3】:

您可以考虑按如下方式替换这些人工制品:

    spring-cloud-stream-schema:在this commit 中,它已更改为spring-cloud-schema-registry-core,因为它的坐标已更改。考虑改用那个。 spring-cloud-starter-eureka:此启动器已弃用并已从 BOM 中删除 in this commit 您可以考虑切换到 spring-cloud-starter-netflix-eureka-clientspring-cloud-sleuth-stream:已弃用,不应再使用。我建议您尝试摆脱它,因为它与某些目的地不兼容,或者只是添加您要使用的版本号,风险自负,直到您可以将其删除。您使用的 Spring Cloud 版本的 BOM 中的版本是 1.3.2.RELEASE

【讨论】:

以上是关于将 Spring Cloud 版本从 Edgware 升级到 Hoxton的主要内容,如果未能解决你的问题,请参考以下文章

将 Spring Cloud Hoxton.SR6 升级到 2020.0.0

spring boot 2.0.0由于版本不匹配导致的NoSuchMethodError问题解析

业余草 SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)(Finchley版本)

Spring Boot 和 Spring Cloud Security OAUTH 2 SSO 在最新版本中失败

Spring Cloud 版本 Hoxton.SR5 默认将 XML 格式作为 HTTP 响应

微服务与Spring Cloud基本概念Spring Cloud版本命名方式与版本选择