An overview of the

We haven’t updated the SpringCloud Alibaba series for a long time. Today we will update the version to the latest graduation version. In addition, seATA, NACOS and Sentinel components, which were originally containerized, were pulled out and deployed separately to prepare for k8S deployment.

The official recommended versions are as follows:

This article mainly describes some problems encountered during the upgrade process and describes the process and methods to solve the problem. Please refer to the previous article for more details.

Major Version Upgrade

<properties>.<spring-boot.version>2.2.5. RELEASE</spring-boot.version>
	<alibaba-cloud.version>2.2.1. RELEASE</alibaba-cloud.version>
	<springcloud.version>Hoxton.SR3</springcloud.version>.</properties>
Copy the code

Modify the component version corresponding to the main POM file of the parent module, and then download the JAR package again.

Nacos 1.2

Upgrading nacOS is easy and can be done in two steps.

  • Initialize the NACOS databasenacos-mysql.sql
  • Modify the nacOS configuration fileapplication.properties, release the database related configuration comments, and modify their own database configuration

1.2 seata

The seATA initialization process is explained in detail in the previous tutorial, but there are significant differences between the old version and the new version. You can follow these steps to complete the initialization process.

  • Create data table undo_log in business systems, SQL file from the following address: https://github.com/seata/seata/blob/develop/script/client/at/db/mysql.sql

  • In your mysql database created in the library, called seata and initialize, SQL file from the following address: https://github.com/seata/seata/blob/develop/script/server/db/mysql.sql

  • The new version of SeATA has changed artifactId, so we need to change the seATA dependencies

<dependency>
	<groupId>com.alibaba.cloud</groupId>
	<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>
Copy the code

SpringCloud Alibaba 2.2.1 RELEASE uses Seata 1.1. If you want to experience the features of Seata 1.2, you can remove the dependency of SeATA on this basis and manually add seata 1.2.

<dependency>
	<groupId>com.alibaba.cloud</groupId>
	<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
	<exclusions>
		<exclusion>
			<artifactId>seata-spring-boot-starter</artifactId>
			<groupId>io.seata</groupId>
		</exclusion>
	</exclusions>
</dependency>

<dependency>
	<groupId>io.seata</groupId>
	<artifactId>seata-spring-boot-starter</artifactId>
	The < version > 1.2.0 < / version >
</dependency>
Copy the code
  • Modify the seata client configuration

    Originally we are using on the client sideregistry.confAs a seATA configuration file, you now need to move the configuration to application.yml or configuration center. For details, you can refer to the official websitehttps://github.com/seata/seata/blob/develop/script/client/spring/application.yml, my configuration is as follows:
seata:
  enabled: true
  application-id: ${spring.application.name}
  tx-service-group: account_service_group
  enable-auto-data-source-proxy: true
  config:
    type: nacos
    nacos:
      namespace:
      serverAddr: 10.023.48.: 8848
      group: SEATA_GROUP
      userName: "nacos"
      password: "nacos"
  registry:
    type: nacos
    nacos:
      application: seata-server
      server-addr: 10.023.48.: 8848
      namespace:
      userName: "nacos"
      password: "nacos"
Copy the code

Other modules are modified by ourselves.

  • Push seATA’s configuration to NACOS. For details about how to use db mode, see the official instructions: github.com/seata/seata…
service.vgroupMapping.account_service_group=default service.vgroupMapping.product_service_group=default service.vgroupMapping.order_service_group=default store.mode=db store.db.datasource=druid store.db.dbType=mysql Store. Db. DriverClassName = com) mysql). The JDBC Driver store. The url = JDBC: mysql: / / 10.0.23.48:3306 / seata? useUnicode=true store.db.user=root store.db.password=xxxxxx store.db.minConn=5 store.db.maxConn=30 store.db.globalTable=global_table store.db.branchTable=branch_table store.db.queryLimit=100 store.db.lockTable=lock_table store.db.maxWait=5000Copy the code

After the modification is complete, run the shell command sh nacos-config.sh -h 10.0.23.48 -p 8848 -g SEATA_GROUP -u nacos -w nacos in Git. After the modification is complete, the configuration file is pushed to nacOS

  • Modify the SeATA server configurationregistry.conf, and then start the Seata server
Registry {type = "nacos" nacos {application = "seata-server" serverAddr = "10.0.23.48.8848" namespace = "" cluster = "Default" username = "nacos" password = "nacos"}} config {type = "nacos" nacos {serverAddr = "10.0.23.48.8848" namespace = "" group = "SEATA_GROUP" username = "" password = "" } }Copy the code
  • After the above steps to configure seATA to complete the upgrade, please test yourself

Sentinel 1.7

When using Sentinel, many students will encounter the situation that the Sentinel console does not display the API management menu and cannot read the NACOS flow limiting configuration. You can add the startup parameter -dcsp.sentinel.app. type=1 when the Gateway module starts. Restart the Sentinel console.

As mentioned in the previous article, the gateway id obtained by Sentinel is not the account-service we configured, but is prefixed with a CompositeDiscoveryClient_. The original explanation is as follows:

This problem is no longer present in the new version, so we can remove the prefix in the gateway traffic limiting profile. The configuration after deletion is as follows:

auth-service

Use the postman to auth – service when acquiring the access_token if appear the following error org. Springframework. Security. Core. Authority. SimpleGrantedAuthority; local class incompatible: stream classdesc serialVersionUID = 510, local class serialVersionUID = 520

The reason for this problem is that the database already stores the access_token corresponding to the account, but SpringSecurity does not support serialization across versions. The solution is as simple as deleting the access_token corresponding to your user and regenerating it.

SpringCloud Gateway

When using PostMan for integration tests, I Found that the interface calls kept prompting 404 Not Found errors.

Through to the source file org.springframework.cloud.gateway.filter.Net tyRoutingFilter debugging, found the new version of the SpringCloud forwarding Gateway doing still we configure the prefix.

As shown in the figure above, the request path cannot be found with the prefix after forwarding, so a 404 exception occurs.

To solve this problem, we need to delete this prefix before forwarding. SprtingCloud Gateway just provides StripPrefix GatewayFilter filter, which can be used to solve this problem:

The StripPrefix GatewayFilter factory takes one parameter, parts. The parts parameter indicates the number of parts in the path to strip from the request before sending it downstream.

For details, see cloud.spring. IO /spring-clou…

Now that you know the cause of the exception and have found a solution, it’s easy. Just add the default filter when configuring the gateway module mapping:

spring:
  cloud:
	gateway:
      discovery:
        locator:
          enabled: true
      routes:
      - id: account-service
        uri: lb://account-service
        predicates:
          - Path=/account-service/**
		.
      # Fix prefix forwarding
      default-filters:
        - StripPrefix=1
Copy the code

After the above steps, we have completed the upgrade of SpringCloud Alibaba, during which we will encounter various problems. When facing the problems, we should not be impatient and try to locate the problems through code debugging. After locating the problems, I believe it can be solved by making good use of search engines.