第一章 SpringCloud Alibaba简介——学习笔记
一、SpringCloud系统版本认识
1、SpringCloud版本发布时间统计
springcloud官方网站:https://spring.io/
1.1、SpringCloud的版本更新发布时间(统计时间2020.04.28)
Angel版本:2015年3月
Brixton版本:2016年5月
Camden版本:2016年9月
Dalston版本:2017年4月
Finchley版本:2018年6月
Greenwich.RELEASE:2019年1月
Hoxton.RELEASE :2019年11月(目前最新版本Hoxton.SR4)
1.2、SpringCloud与Spring-boot的maven仓库的版本列表
spring-cloud-dependencies 版本列表可查看:
https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies
spring-boot-starter-parent版本列表可查看:
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent
注意事项:
初学spring cloud的朋友可能不知道,其实SpringBoot与SpringCloud需要版本对应,否则可能会造成很多意料之外的错误,比如eureka注册了结果找不到服务类啊,比如某些jar导入不进来啊,等等这些错误。下面列出来springBoot和spring cloud的版本对应关系,需要配套使用,才不会出现各种奇怪的错误。
2、SpringBoot和SpringCloud的版本对应关系
2.1、大致版本对应关系
SpringCloud 版本 |
SpringBoot版本 |
Angel版本 |
兼容Spring Boot 1.2.x |
Brixton版本 |
兼容Spring Boot 1.3.x,也兼容Spring Boot 1.4.x |
Camden版本 |
兼容Spring Boot 1.4.x,也兼容Spring Boot 1.5.x |
Dalston版本、Edgware版本 |
兼容Spring Boot 1.5.x,不兼容Spring Boot 2.0.x |
Finchley版本 |
兼容Spring Boot 2.0.x,不兼容Spring Boot 1.5.x |
Greenwich版本 |
兼容Spring Boot 2.1.x |
Hoxton版本 |
兼容Spring Boot 2.2.x |
spring-cloud-alibaba版本2.2.0.RELEASE |
Spring Boot >=2.2.0.RELEASE and <2.3.0.M1 |
2.2、在实际开发过程中,我们需要更详细的版本对应
Edgware.SR5 |
1.5.16.RELEASE |
Edgware.SR5 |
1.5.20.RELEASE |
Finchley.M2 |
Spring Boot >=2.0.0.M3 and <2.0.0.M5 |
Finchley.M3 |
Spring Boot >=2.0.0.M5 and <=2.0.0.M5 |
Finchley.M4 |
Spring Boot >=2.0.0.M6 and <=2.0.0.M6 |
Finchley.M5 |
Spring Boot >=2.0.0.M7 and <=2.0.0.M7 |
Finchley.M6 |
Spring Boot >=2.0.0.RC1 and <=2.0.0.RC1 |
Finchley.M7 |
Spring Boot >=2.0.0.RC2 and <=2.0.0.RC2 |
Finchley.M9 |
Spring Boot >=2.0.0.RELEASE and <=2.0.0.RELEASE |
Finchley.RC1 |
Spring Boot >=2.0.1.RELEASE and <2.0.2.RELEASE |
Finchley.RC2 |
Spring Boot >=2.0.2.RELEASE and <2.0.3.RELEASE |
Finchley.SR4 |
Spring Boot >=2.0.3.RELEASE and <2.0.999.BUILD-SNAPSHOT |
Finchley.BUILD-SNAPSHOT |
Spring Boot >=2.0.999.BUILD-SNAPSHOT and <2.1.0.M3 |
Greenwich.M1 |
Spring Boot >=2.1.0.M3 and <2.1.0.RELEASE |
Greenwich.SR2 |
Spring Boot >=2.1.0.RELEASE and <2.1.9.BUILD-SNAPSHOT |
Greenwich.SR5 |
Spring Boot >=2.1.0.RELEASE and <2.1.14.BUILD-SNAPSHOT |
Greenwich.BUILD-SNAPSHOT |
Spring Boot >=2.1.14.BUILD-SNAPSHOT and <2.2.0.M4 |
Hoxton.M2 |
Spring Boot >=2.2.0.M4 and <=2.2.0.M5 |
Hoxton.SR4 |
Spring Boot >=2.2.0.M4 and <2.3.0.BUILD-SNAPSHOT |
Hoxton.BUILD-SNAPSHOT |
Spring Boot >=2.3.0.BUILD-SNAPSHOT |
具体信息如下所示:版本信息获取接口:https://start.spring.io/actuator/info
{
"git": {
"commit": {
"time": "2020-04-27T15:05:42Z",
"id": "76b83f5"
},
"branch": "76b83f5b9bef30178470ef38f74091720a41153b"
},
"build": {
"version": "0.0.1-SNAPSHOT",
"artifact": "start-site",
"name": "start.spring.io website",
"versions": {
"initializr": "0.9.0.BUILD-SNAPSHOT",
"spring-boot": "2.2.6.RELEASE"
},
"group": "io.spring.start",
"time": "2020-04-27T15:07:31.953Z"
},
"bom-ranges": {
"azure": {
"2.0.10": "Spring Boot >=2.0.0.RELEASE and <2.1.0.RELEASE",
"2.1.7": "Spring Boot >=2.1.0.RELEASE and <2.2.0.M1",
"2.2.0": "Spring Boot >=2.2.0.M1"
},
"codecentric-spring-boot-admin": {
"2.0.6": "Spring Boot >=2.0.0.M1 and <2.1.0.M1",
"2.1.6": "Spring Boot >=2.1.0.M1 and <2.2.0.M1",
"2.2.1": "Spring Boot >=2.2.0.M1"
},
"solace-spring-boot": {
"1.0.0": "Spring Boot >=2.2.0.RELEASE and <2.3.0.M1"
},
"solace-spring-cloud": {
"1.0.0": "Spring Boot >=2.2.0.RELEASE and <2.3.0.M1"
},
"spring-cloud": {
"Finchley.M2": "Spring Boot >=2.0.0.M3 and <2.0.0.M5",
"Finchley.M3": "Spring Boot >=2.0.0.M5 and <=2.0.0.M5",
"Finchley.M4": "Spring Boot >=2.0.0.M6 and <=2.0.0.M6",
"Finchley.M5": "Spring Boot >=2.0.0.M7 and <=2.0.0.M7",
"Finchley.M6": "Spring Boot >=2.0.0.RC1 and <=2.0.0.RC1",
"Finchley.M7": "Spring Boot >=2.0.0.RC2 and <=2.0.0.RC2",
"Finchley.M9": "Spring Boot >=2.0.0.RELEASE and <=2.0.0.RELEASE",
"Finchley.RC1": "Spring Boot >=2.0.1.RELEASE and <2.0.2.RELEASE",
"Finchley.RC2": "Spring Boot >=2.0.2.RELEASE and <2.0.3.RELEASE",
"Finchley.SR4": "Spring Boot >=2.0.3.RELEASE and <2.0.999.BUILD-SNAPSHOT",
"Finchley.BUILD-SNAPSHOT": "Spring Boot >=2.0.999.BUILD-SNAPSHOT and <2.1.0.M3",
"Greenwich.M1": "Spring Boot >=2.1.0.M3 and <2.1.0.RELEASE",
"Greenwich.SR5": "Spring Boot >=2.1.0.RELEASE and <2.1.14.BUILD-SNAPSHOT",
"Greenwich.BUILD-SNAPSHOT": "Spring Boot >=2.1.14.BUILD-SNAPSHOT and <2.2.0.M4",
"Hoxton.SR4": "Spring Boot >=2.2.0.M4 and <2.3.0.BUILD-SNAPSHOT",
"Hoxton.BUILD-SNAPSHOT": "Spring Boot >=2.3.0.BUILD-SNAPSHOT"
},
"spring-cloud-alibaba": {
"2.2.0.RELEASE": "Spring Boot >=2.2.0.RELEASE and <2.3.0.M1"
},
"spring-cloud-services": {
"2.0.3.RELEASE": "Spring Boot >=2.0.0.RELEASE and <2.1.0.RELEASE",
"2.1.7.RELEASE": "Spring Boot >=2.1.0.RELEASE and <2.2.0.RELEASE",
"2.2.3.RELEASE": "Spring Boot >=2.2.0.RELEASE and <2.3.0.M1"
},
"spring-statemachine": {
"2.0.0.M4": "Spring Boot >=2.0.0.RC1 and <=2.0.0.RC1",
"2.0.0.M5": "Spring Boot >=2.0.0.RC2 and <=2.0.0.RC2",
"2.0.1.RELEASE": "Spring Boot >=2.0.0.RELEASE"
},
"vaadin": {
"10.0.17": "Spring Boot >=2.0.0.M1 and <2.1.0.M1",
"14.1.27": "Spring Boot >=2.1.0.M1"
}
},
"dependency-ranges": {
"okta": {
"1.2.1": "Spring Boot >=2.1.2.RELEASE and <2.2.0.M1",
"1.4.0": "Spring Boot >=2.2.0.M1"
},
"mybatis": {
"2.0.1": "Spring Boot >=2.0.0.RELEASE and <2.1.0.RELEASE",
"2.1.2": "Spring Boot >=2.1.0.RELEASE"
},
"geode": {
"1.2.6.RELEASE": "Spring Boot >=2.2.0.M5 and <2.3.0.M1",
"1.3.0.M4": "Spring Boot >=2.3.0.M1 and <2.3.0.BUILD-SNAPSHOT",
"1.3.0.BUILD-SNAPSHOT": "Spring Boot >=2.3.0.BUILD-SNAPSHOT"
},
"camel": {
"2.22.4": "Spring Boot >=2.0.0.M1 and <2.1.0.M1",
"2.25.1": "Spring Boot >=2.1.0.M1 and <2.2.0.M1",
"3.2.0": "Spring Boot >=2.2.0.M1"
}
}
}
3、Spring Cloud各组件认识
1)Spring Cloud Netflix套件包括:
Eureka、Ribbon、Feign、Hystrix、Zuul
2)Spring Cloud Alibaba套件:
Nacos、Sentinel、RocketMQ
3)Spring Cloud原生及其他整合组件:
Consul、Config、Gateway、Stream、Sleuth/Zipkin
4、查看springcloud计划发布信息:
4.1、springcloud版本发布计划:
https://github.com/spring-cloud/spring-cloud-release/milestones
4.2、发布历史记录:
https://github.com/spring-cloud/spring-cloud-release/releases
4.3、版本结束信息
查看地址:https://spring.io/projects/spring-cloud
二、SpringCloud-Alibaba概念
Spring Cloud Alibaba项目由两部分组成:阿里巴巴开源组件和阿里云产品组件,旨在为Java开发人员在使用阿里巴巴产品的同时,通过利用Spring框架的设计模式和抽象能力,注入Spring Boot和Spring Cloud的优势。Spring Cloud Alibaba项目是由阿里巴巴维护的社区项目。
注意:版本0.2.0.RELEASE对应的是Spring Boot 2.x版本,版本0.1.0.RELEASE对应的是Spring Boot 1.x版本。
1、阿里巴巴开源组件
其中阿里巴巴开源组件的命名前缀为spring-cloud-alibaba,提供了如下特性:
1.1、服务发现
实现了Spring Cloud common中定义的registry相关规范接口,引入依赖并添加一些简单的配置即可将你的服务注册到Nacos Server中,并且支持与Ribbon的集成。
1.2、配置管理
实现了PropertySoureLocator 接口,引入依赖并添加一些简单的配置即可从Nacos Server中获取应用配置并设置在Spring的Environment中,而且无需依赖其他组件即可支持配置的实时推送和推送状态查询。
1.3、高可用防护
默认集成了Servlet、RestTemplate、Dubbo、RocketMQ的限流(Flow Control)降级(Circuit Breaking and Concurrency),只需要引入依赖即可完成限流降级的集成动作,并支持在应用运行状态下通过Sentinel控制台来实时修改限流降级的策略和阈值。
2、阿里云产品组件
阿里云的产品组件的命名前缀为 spring-cloud-alicloud,提供了如下特性:
2.1、应用发现服务
阿里云应用发现服务ANS,除了应用发现的基本功能外,提供了更低成本的SaaS化应用发现服务,同时在接口的调用中加入了加密逻辑,更好地保护你的服务。
2.2、配置管理服务
阿里云配置管理服务ACM,加强了安全的配置管理,并且还包含了完整的推送轨迹查询。
2.3、对象存储服务
阿里云云存储服务OSS,支持在任何应用、任何时间、任何地点存储和访问任意类型的数据,只需要自动注入一个OSS Client,即可直接使用存储与下载功能。
3、如何使用
这些组件在Spring release仓库中,可以通过如下BOM来使用:
4、后续规划
1)spring-cloud-stream-binder-rocket 模块将基于 Spring Integration和Spring Cloud Stream,使得开发者在使用Spring Cloud Stream和Spring Cloud Bus时候可以选择使用RocketMQ作为消息中间件。
2)Spring Cloud Alibaba将集成阿里云分布式任务调度SchedulerX 和阿里云日志服务,支持开发者使用 Spring Boot编程模型简化其使用。
据 Spring Cloud Alibaba高级开发工程师亦盏介绍,Spring Cloud本身是一套微服务规范,并不是一个拿来即可用的框架,而 Spring Cloud Alibaba的开源为开发者们提供了这套规范的实现方式。同时Spring Cloud Alibaba的组件,孵化自阿里巴巴内部自用的中间件产品,经历过多次双十一的考验,具备高并发的抗压能力。此外,其完整的中文文档和本地化的开源服务将提高开发者们的接入速率,并降低后续的运维难度。
5、Spring Cloud Alibaba版本兼容性:
下表整理了目前Spring Cloud Alibaba的版本与Spring Boot、Spring Cloud版本的兼容关系:
版本说明:
https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E
5.1、组件版本关系:
5.2、毕业版本依赖关系(推荐使用)
5.3、依赖管理
Spring Cloud Alibaba BOM 包含了它所使用的所有依赖的版本。
RELEASE版本:
1)Spring Cloud Hoxton
如果需要使用 Spring Cloud Hoxton 版本,请在 dependencyManagement 中添加如下内容
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.2.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
2)Spring Cloud Greenwich
如果需要使用 Spring Cloud Greenwich 版本,请在 dependencyManagement 中添加如下内容
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.1.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
3)Spring Cloud Finchley
如果需要使用 Spring Cloud Finchley 版本,请在 dependencyManagement 中添加如下内容
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.0.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
注意:孵化器版本依赖关系(不推荐使用)