Preface: Spring Cloud Alibaba is the mainstream distributed micro-service architecture at present. This paper mainly explains how to build Spring Cloud Alibaba environment in IDEA. It also introduces the relationship between various versions of Spring Cloud Alibaba and the preparatory work before setting up Spring Cloud.
Spring Cloud Alibaba Official Documentation (Chinese)
Spring Cloud website
Lead to
Spring Cloud Alibaba needs to rely on the Java environment to run, and also need to configure the Maven environment to ensure the following version:
- JDK 1.8+ : Install
- Maven 3.2.x+ : Installation
Release notes
Check the release notes on the official website
Component Version relationship
In the following figure, you do not need to set the dependencies of Spring-cloud-alibaba-dependencies, which are already configured in Spring Cloud Alibaba version manager
Graduate version dependencies (recommended)
Different Versions of Spring Cloud Alibaba have different version dependencies. When creating Spring Cloud Alibaba, you need to check the instructions on the official website and select RELEASE version.
Building methods
pom.xml
< the properties > < spring. Cloud. Alibaba. Version > 2.2.6. RELEASE < / spring. Cloud. Alibaba. Version > < spring. The boot. Version > 2.3.2. RELEASE < / spring. The boot. Version > < spring. Cloud. Version > Hoxton. SR9 < / spring. Cloud - version > </properties> <dependencyManagement> <dependencies> <! --> <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> <! <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 - > < the 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>Copy the code
Spring-boot-starter-parent dependencies are the same as spring-boot-starter-parent dependencies
Spring Scaffold creation
Build items: Convention > Configuration > Code
The parent project
- Create a new parent project in IDEA (the parent project is used to contract the release of the entire SpringCloud project)
- Choose the 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
Files, onlypom.xml
File, parent project enough to use
- Select the Spring Boot version (optional, need to change later)
- Check the project name and save location, and click Finish. Wait until the creation is complete. If the page is displayed, the creation is complete
- After creation, open it
pom.xml
Add the following content to the file to add the dependencies of SpringCloudAlibaba, SpringBoot and SpringCloud
pom.xml
< the properties > < spring. Cloud. Alibaba. Version > 2.2.6. RELEASE < / spring. Cloud. Alibaba. Version > < spring. The boot. Version > 2.3.2. RELEASE < / spring. The boot. Version > < spring. Cloud. Version > Hoxton. SR9 < / spring. Cloud - version > </properties> <dependencyManagement> <dependencies> <! --> <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> <! <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 - > < the 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>Copy the code
Spring-boot-starter-parent dependencies are the same as spring-boot-starter-parent dependencies
- The parent project is completed, others are as followsService discovery registry, configuration center, message bus, load balancer, circuit breaker, data monitoringSuch components are required in the parent project
pom.xml
To introduce the dependency, here will be skipped
The child module
- Create a new module in the parent project
- Select Maven and click Next.
- Fill in the submodule name (service name)
Compared with Spring’s official scaffolding, it is more convenient to use Ali Cloud scaffolding to create, ali Cloud focuses on micro service projects
The IDEA of setting up
Add the Services TAB for SpringBoot
Quickly manage the status of each service
- Edit the configuration
- Example Add the SpringBoot service
- Find SpringBoot
- After clicking OK, a “Services” will appear below to view the Spring Boot microservice status
The service name
- Right click on the service and select the red box below to open it
- Modifying Configuration Information