SpringCloudAlibaba - 整合 Spring Cloud Alibaba
目录
前言
Spring Cloud Alibaba
是SpringCloud
的子项目,是阿里的微服务解决方案,致力于提供微服务开发的一站式解决方案,包括微服务开发的必备组件。
Spring Cloud Alibaba
的整合包括两步:
1、整合SpringCloud
2、整合SpringCloud Alibaba
整合步骤
版本与兼容性
Spring Cloud Alibaba
基于Spring Cloud
,而Spring Cloud
基于Spring Boot
Spring Cloud Alibaba 版本说明
Spring Cloud Alibaba
版本说明: spring-cloud-alibaba版本说明
- 如上,目前最新版本是:
Spring Cloud 2020.0.1
+Spring Cloud Alibaba 2021.1
+Spring Boot 2.4.2
,本着不做第一批吃螃蟹的原则,选择Spring Cloud Hoxton.SR9
+Spring Cloud Alibaba 2.2.6.RELEASE
+Spring Boot 2.3.2.RELEASE
吧(悄么告诉你们,我是发现Spring Cloud 2020
已经不再支持Ribbon
了,我才回退版本的。。。)
Spring Cloud 版本说明
Spring Cloud
版本说明:Spring Cloud 版本说明
- 如上,我们选择的
Spring Cloud
版本为Hoxton
, 对应的Spring Boot
版本为2.2.x, 2.3.x
So,我们这里的整合版本是:
Spring Cloud Hoxton.SR9
+ Spring Cloud Alibaba 2.2.6.RELEASE
+ Spring Boot 2.3.2.RELEASE
整合Spring Cloud
pom.xml
<properties>
<spring-cloud.version>Hoxton.SR9</spring-cloud.version>
</properties>
<dependencyManagement>
<dependencies>
<!--整合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>
<dependencies>
</dependencyManagement>
整合Spring Cloud Alibaba
pom.xml
<properties>
<spring-cloud-alibaba.version>2.2.6.RELEASE</spring-cloud-alibaba.version>
</properties>
<dependencyManagement>
<dependencies>
<!--整合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>
完整pom文件
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.coisini</groupId>
<artifactId>user-center</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>user-center</name>
<description>user-center project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR9</spring-cloud.version>
<spring-cloud-alibaba.version>2.2.6.RELEASE</spring-cloud-alibaba.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<!-- 整合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>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
编译
- 项目编译
mvn clean install
...至此,Spirng Cloud Alibaba
已整合进项目中
项目源码
GitHub
: https://github.com/Maggieq8324/coisini-cloud-alibabaGitee
: https://gitee.com/maggieq8324/coisini-cloud-alibaba