Spring Cloud Alibaba is the mainstream distributed microservice architecture at present. This paper mainly explains how to build Spring Cloud Alibaba environment in IDEA, introduces the relationship between various versions of Spring Cloud Alibaba and the preparations before building Spring Cloud.
Spring Cloud Alibaba official document (Chinese)
Pre preparation
Spring Cloud Alibaba needs to rely on the Java environment and configure Maven environment to ensure the following versions:
Version Description
View the on the official website Version Description
Component version relationship
The version relationship in the figure below does not need to be set by yourself. Spring Cloud Alibaba dependencies have been configured in the Spring Cloud Alibaba version manager, and the dependency can be introduced
Graduation version dependency (recommended)
Different versions of spring cloud and Alibaba have different version dependencies. You need to view them when creating them Official website description , select RELEASE version
Construction method
pom.xml
<properties> <spring.cloud.alibaba.version>2.2.6.RELEASE</spring.cloud.alibaba.version> <spring.boot.version>2.3.2.RELEASE</spring.boot.version> <spring.cloud.version>Hoxton.SR9</spring.cloud-version> </properties> <dependencyManagement> <dependencies> <!--Spring Cloud Alibaba Version Manager--> <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> <!--Spring Boot Version Manager--> <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 Version Manager--> <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>
Spring Boot dependencies and Spring Boot starter parent in the Spring Boot version manager are the same. Both names can be used
Spring scaffold creation
Build project: contract > configuration > coding
Parent project
- Create a new parent project in the IDEA (the parent project is used to agree the version of the entire spring cloud project)
- Select Spring Initializr
- Fill in the project information. Note: select Maven POM and Java version (JDK)
Selecting Maven POM to create a project will not create src file, only pom.xml file, which is enough for the parent project
- Select the Spring Boot Version (select it casually and need to be modified later)
- Check the project name and save location, and click Finish. Wait for the creation to be completed, and the creation will be completed when the interface appears
- After creation, open the pom.xml file, add the following contents, and add the dependencies of SpringCloudAlibaba, SpringBoot and SpringCloud
pom.xml
<properties> <spring.cloud.alibaba.version>2.2.6.RELEASE</spring.cloud.alibaba.version> <spring.boot.version>2.3.2.RELEASE</spring.boot.version> <spring.cloud.version>Hoxton.SR9</spring.cloud-version> </properties> <dependencyManagement> <dependencies> <!--Spring Cloud Alibaba Version Manager--> <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> <!--Spring Boot Version Manager--> <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 Version Manager--> <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>
Spring Boot dependencies and Spring Boot starter parent in the Spring Boot version manager are the same. Both names can be used
- After the parent project is built, other components such as service discovery and registration, configuration center, message bus, load balancing, circuit breaker and data monitoring can be introduced into the pom.xml of the parent project if necessary. This is omitted first
Sub module
- Create a new module in the parent project
- Select Maven and click Next.
- Fill in sub module name (service name)
Compared with the scaffold officially provided by Spring, the Alibaba cloud scaffold It will be faster and more convenient to create. Alibaba cloud focuses on micro service projects
IDEA settings
Add the Services tab of SpringBoot
Quickly manage the status of each service
- Edit configuration
- Add SpringBoot service
- Find SpringBoot
- After clicking OK, a service will appear below to view the microservice status of Spring Boot
Service renaming
- Right click the service and select the red box in the figure below to open it
- Modify configuration information