【SpringCloud】3. Spring Cloud环境搭建

382 阅读2分钟

版本命名

Spring Cloud是一个由众多独立子项目组成的大型综合项目,原则每个子项目上有不同的发布节奏,都维护自己发布版本号。为了更好的管理Spring Cloud的版本,通过一个资源清单BOM(Bill of Materials),为避免与子项目的发布号混淆,所以没有采用版本号的方式,而是通过命名的方式。这些名字是按字母顺序排列的。如伦敦地铁站的名称(“天使"是第一个版本,“布里斯顿"是第二个版本,"卡姆登"是第三个版本等)。当单个项目的点发布累积到一个临界量,或者其中一个项目中有一个关键缺陷需要每个人都可以使用时,发布序列将推出名称以".SRX"结尾的"服务发布”,其中"X"是一个数字(例如当前版本为:Hoxton.SR8)。

伦敦地铁站名称:Angel、Brixton、Camden、Dalston、Edgware、Finchley、Greenwich、Hoxton

Spring Boot和Spring Cloud版本适配

  • Angel:版本基于springboot1.2.x版本构建与1.3版本不兼容。
  • Brixton:版本基于springboot1.3.x版本构建与1.2版本不兼容。
  • 2017年Brixton and Angel release官方宣布报废。
  • Camden:版本基于springboot1.4.x版本构建并在1.5版本通过测试。
  • 2018年Camden release官方宣布报废。
  • Dalston、Edgware:版本基于springboot1.5.x版本构建,目前不能在springboot2.0.x版本中使用。
  • 2018年12月Dalston release官方宣布报废。
  • Finchley:版本基于springboot2.0.x版本进行构建,不能兼容1.x版本。
  • Greenwich:版本基于springboot2.1.x版本进行构建,不能兼容1.x版本。
  • Hoxton:版本基于springboot2.2.x版本进行构建。

基础环境搭建

  1. 项目地址:

  2. 说明:

    1. IDEA:2020
    2. Maven:3.6.3
    3. JDK:8
    4. Spring Boot:2.2.5
    5. Spring Cloud:Hoxton.SR6
  3. 搭建基础环境

    说明:每一个组件都需要搭建Spring Cloud基础环境,搭建位置在工程或者模块中的pom.xml文件中。

    步骤:

    1. 如果是父工程:创建Empty Project。
    2. 如果是服务:
      1. 在父工程中使用Spring Initializr构建模块。
      2. 删除模块中相关文件,只保留src文件夹,pom.xml和xxxx.iml文件。
      3. 配置pom.xml搭建Spring Cloud基础环境。

服务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.2.5.RELEASE</version>
           <relativePath/> <!-- lookup parent from repository -->
       </parent>
       <groupId>org.aydenbryan</groupId>
       <artifactId>environment</artifactId>
       <version>0.0.1-SNAPSHOT</version>
       <name>environment</name>
       <description>Demo project for Spring Boot</description>
       <properties>
           <java.version>1.8</java.version>
           <!--  SpringCloud具体版本  -->
           <spring.cloud.version>Hoxton.SR6</spring.cloud.version>
       </properties>
       <dependencies>
           <!--  依赖根据组件的需要动态选择  -->
           <dependency>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-starter-web</artifactId>
           </dependency>
       </dependencies>
   
       <build>
           <plugins>
               <plugin>
                   <groupId>org.springframework.boot</groupId>
                   <artifactId>spring-boot-maven-plugin</artifactId>
                   <configuration>
                       <excludes>
                           <exclude>
                               <groupId>org.projectlombok</groupId>
                               <artifactId>lombok</artifactId>
                           </exclude>
                       </excludes>
                   </configuration>
               </plugin>
           </plugins>
       </build>
   
       <!--  配置Spring仓库服务器,解决SpringBoot2.2.5在maven仓库中找不到的问题  -->
       <repositories>
           <repository>
               <id>spring-snapshots</id>
               <url>http://repo.spring.io/libs-snapshot</url>
           </repository>
       </repositories>
       <pluginRepositories>
           <pluginRepository>
               <id>spring-snapshots</id>
               <url>http://repo.spring.io/libs-snapshot</url>
           </pluginRepository>
       </pluginRepositories>
   
       <!--  全局管理SpringCloud版本,给SpringCloud组件提供下载位置  -->
       <dependencyManagement>
           <dependencies>
               <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>
   </project>