整合Spring Cloud Alibaba
前言
Spring Cloud Alibaba
是 SpringCloud
的子项目,也是阿里巴巴的微服务
解决方案,致力于提供微服务开发的一站式解决方案,包括微服务开发的必备组件。
Spring Cloud Alibaba
的整合包括两步:(整合SpringCloud、整合Spring Cloud Alibaba)
开始整合
版本与兼容性
Spring Cloud Alibaba
基于 Spring Cloud
,而 Spring Cloud
基于 Spring Boot
Spring Cloud Alibaba 版本说明
Spring Cloud Alibaba
版本说明: spring-cloud-alibaba版本说明
如上,目前最新版本是:Spring Cloud 2021.0.1
+ Spring Cloud Alibaba 2021.0.1.0
+ Spring Boot 2.6.3
,本着不做第一批吃螃蟹的原则,选择Spring Cloud Hoxton.SR12
+ Spring Cloud Alibaba 2.2.7.RELEASE
+ Spring Boot 2.3.12.RELEASE
吧
Spring Cloud 版本说明
Spring Cloud
版本说明:Spring Cloud 版本说明
如上,我们选择的Spring Cloud
版本为Hoxton
, 对应的Spring Boot
版本为2.2.x, 2.3.x
所以,我们这里整合的版本是:
Spring Cloud Hoxton.SR12
+ Spring Cloud Alibaba 2.2.7.RELEASE
+ Spring Boot 2.3.12.RELEASE
整合Spring Cloud
.pom.xml
<properties>
<spring-cloud.version>Hoxton.SR12</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.7.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.12.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.SR12</spring-cloud.version>
<spring-cloud-alibaba.version>2.2.7.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
已整合进项目中