回顾
延续上文,我们提及到了SpringCloud的一系列组件,今天我总结一下在使用过程中 对版本的依赖。
复制代码
前提
首先我们要知道的是SpringCloud他是按照伦敦地铁站命名方式来阐述版本的,在对其开发的时候需要注意他各个版本需要依赖的组件版本是一样的。不能上来随便选择几个版本组件进行依赖的。
在官网中他是这样阐述的:
以上说明了,开发的时候可以更具Release Trains命名约定的信息来选择版本。
以上是他的历史版本,其中也强调了Hoxton will be the last named release train.(H版本就是最后一个版本),后续的更新SpringCloud团队将以年月日加更改接点来发布新的版本。
开始走近SpringCloud
1.查看版本
大家需要更具自己想要的版本去选择对应的组件版本目前我选择的是官网提供的spring-cloud-2020-0-0-m1-released版本。
以下是官网对应当前我选择的版本所做出各组件的推荐版本:
如果有一个现有的Spring Boot应用程序,想要将Spring Cloud添加到该应用程序中,第一步是确定您应该使用的Spring Cloud版本。Spring Cloud与Spring Boot的对应表:
2.Maven的引入
Maven对组件的依赖如下图(也是官网给出的案例):
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2020.0.0-M1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!-- ... -->
</dependencies>
复制代码
2.Gradle的引入
在官网中也给予了代码提供
plugins {
id 'org.springframework.boot' version '2.3.0.M4'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
}
ext {
set('springCloudVersion', "2020.0.0-M1")
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
dependencies {
compile 'org.springframework.cloud:spring-cloud-starter-config'
compile 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
//...
}
复制代码
总结
从上可以看出,在我们开发之前,可以去对应的官网了解到他的基本知识,越是多组件的开发,我们就应该越是在开始的时候去确立我们要搭建的版本,去了解个版本的优势,选择适合的稳定的版本在此之上进行开发。
强调:我要强调一遍官方文档是我们最好的老师!!!