头图
A while ago, I fully upgraded the mall project to support SpringBoot 2.7.0. I believe many friends already know it. Recently, I took the time to upgrade its microservice version mall-swarm and it supports the latest version of SpringCloud&Alibaba. Today, I will talk about the upgrade content and some problems encountered during the upgrade process, and I hope it will be helpful to everyone!

SpringCloud actual e-commerce project mall-swarm (8.8k+star) address: https://github.com/macrozheng/mall-swarm

Technology stack upgrade

mall-swarm As the microservice version of the mall project, the implementation functions are basically the same as the mall project, but the architecture is different. Therefore, the upgraded technology in the mall project, mall-swarm has also been basically upgraded. Here are some key points to mention. For other upgrade information, please refer to the comprehensive upgrade of the mall project .
technology Version illustrate
Spring Cloud Hoxton.SR5->2021.0.3 Microservice Framework
Spring Cloud Alibaba 2.2.0->2021.0.3 Microservice Framework
Spring Boot 2.3.0->2.7.0 Container + MVC framework
Spring Security Oauth2 2.2.2->2.2.5 Authentication and Authorization Framework
MyBatis 3.4.6->3.5.9 ORM framework
Knife4j 2.0.4->3.0.3 document production tool
Nacos 1.3.1->2.1.0 Registration Center and Configuration Center
Spring Boot Admin 2.3.0->2.7.0 Microservice monitoring

upgrade process

Here are some problems encountered during the upgrade process, you can refer to it!

Support SpringBoot 2.7.0

Since the mall-swarm project uses Spring Cloud Gateway+Oauth2 to achieve a unified authentication and authorization solution, the circular dependency problem in the mall project does not appear here. Upgrading SpringBoot 2.7.0 is quite smooth, and it is directly supported by default!

Support for SpringCloud 2021

After upgrading Spring Cloud 2021, an important component in Spring Cloud has been deprecated, that is Ribbon as a load balancing component. In services that require inter-service calls, such as gateway services, we need to add LoadBalancer dependencies:

 <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>

Otherwise, when calling between services, it will return Service Unavailable error message.

 {
    "timestamp": "2022-06-28T02:36:31.680+00:00",
    "path": "/auth/oauth/token",
    "status": 503,
    "error": "Service Unavailable",
    "requestId": "c480cefa-1"
}

Support Nacos 2.1.0

The previous project used Nacos as the registration center and configuration center. This time, the version was upgraded from 1.3.1 to the latest version 2.1.0 . The above has basically not changed, except that it needs to be added when starting Nacos on Windows. standalone parameter.

 startup.cmd -m standalone

Below is a screenshot of using Nacos as the configuration center.

Microservice permission solution upgrade

The microservice permission solution has been upgraded to adapt to the latest version of Spring Cloud. Implementation ideas: mall-auth Authentication service is responsible for unified authentication, mall-gateway Gateway service is responsible for verification and authentication, and other APIs Services (such as mall-admin, mall-portal) are responsible for handling their own business logic. Permission-related logic only exists in authentication services and gateway services, and other services simply provide services without any permission-related logic. For details, please refer to Support Nacos 2.1.0! This Spring Cloud Gateway+Oauth2 ultimate authority solution has been upgraded! .

Knife4j upgrade

Upgraded the version of Knife4j, from 2.x to 3.x , because Knife4j is basically a Swagger with a new skin, so as long as you solve the problem of the previous Swagger upgrade, you can refer to the upgrade for details. After SpringBoot 2.6.x version, Swagger can't be used! .

Take a look at the page of the new version of Knife4j, which is basically the same as the previous version.

Microservice monitoring upgrade

mall-swarm Use Spring Boot Admin as microservice monitoring, and the usage after upgrade is basically the same as before.

Deployment Documentation Updates

mall-swarm The deployment document of the project has also been updated synchronously. For details, please refer to the following link.
  • Deployment of mall-swarm in Windows environment
https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_windows.html
  • Deployment of mall-swarm in Linux environment (based on Docker container)
https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_docker.html

Running effect demonstration

Some friends may not know this project yet, here is the demonstration effect of the mall-swarm e-commerce project.
  • Use Nacos as the registration configuration center;

  • Use Knife4j as an API interface documentation tool;

  • Microservice application monitoring system;

  • Microservice log collection system;

  • Microservice application container management.

Summarize

Today I shared a bit about mall-swarm the upgrade content of the project and some problems encountered in the upgrade process, and the transition can basically be smooth. Since the date is used as the version number, I always feel that the version number of Spring Cloud looks a bit confusing, and the latest stable version is currently 2021, and the 2022 version is estimated to be on the way.

Project source code address

Open source is not easy, friends who think the project is helpful, please click Star to support it!

https://github.com/macrozheng/mall-swarm


macrozheng
1.1k 声望1.3k 粉丝