1

Preface

I have been using SpringCloud Hoxton.SR4 version and SpringBoot 2.2.5.RELEASE version. Since SpringCloud upgraded to 2020.0, I would like to try to upgrade, and record the problems encountered to share with you

Version comparison

There is a SpringCloud and SpringBoot comparison version official website. I upgraded it with reference to this version.
image.png
image.png
The following is to show the SpringCloud version comparison

image.png
The following is the
Nacos corresponding SpringCloud and SpringBoot version comparison table :
image.png

So I chose the SpringCloud version is 2020.0.0 , SpringBoot version is 2.4.2 , Alibaba version is 2021.1 , here we come to the upgrade.

Start to upgrade

Introduce related dependency packages

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.2</version>
</parent>
<properties>
    <java.version>1.8</java.version>
    <spring-boot.version>2.4.2</spring-boot.version>
    <spring-cloud.version>2020.0.0</spring-cloud.version>
    <spring-cloud-alibaba.version>2021.1</spring-cloud-alibaba.version>
</properties>
<dependencyManagement>
    <dependencies>
        <!-- spring boot 依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>${spring-boot.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <!-- spring cloud 依赖 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <!-- spring cloud alibaba 依赖 -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-alibaba-dependencies</artifactId>
            <version>${spring-cloud-alibaba.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-oauth2</artifactId>
        <version>2.2.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-security</artifactId>
        <version>2.2.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-loadbalancer</artifactId>
    </dependency>
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
    </dependency>
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
    </dependency>
    <!-- 添加对bootstrap.yml支持 -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-bootstrap</artifactId>
    </dependency>
</dependencies>

Problems encountered during the upgrade

  • 1. Some dependent package versions have to be written dead, such as spring-cloud-starter-oauth2, because the spring-cloud-security-dependencies dependency is removed from cloud2020.0.0 and above.
  • 2. Pom introduces the spring-cloud-starter-bootstrap package, otherwise bootstrap.yml will not work,
  • 3. Add the service attribute to nacos discovery, otherwise an error will be reported, as shown below:
spring:
  application:
    name: aaa
  profiles:
    active: test
  cloud:
    nacos:
      discovery:
        server-addr: http://nacos-host:8848
        namespace: xxx-xxx-xxx
        service: aaa
      config:
        server-addr: http://nacos-host:8848
        file-extension: yaml
        prefix: aaa
        namespace: xxx-xxx-xxx
server:
  port: 8901

to sum up

  • 1. The spring-cloud--starter-oauth2 package of the previous version is gone, and the corresponding one is not found. The reference packages spring-security-oauth2 and spring-security-oauth2-autoconfigure can also implement the oauth2 server function, but the related class prompts expire.
  • 2. In the previous version, when spring cloud bus and mq were used together, it was impossible to use stream3.0 to receive messages. Now this problem has been solved.
  • Except eureka, other netflix components have been deleted

Quote

SpringCloud upgrade to 2020 record
error dependencies.dependency.version is missing
Spring Cloud Alibaba upgrade to 2.1.0 pits encountered
nacos release notes
springcloud version comparison


Awbeci
3.1k 声望212 粉丝

Awbeci