天天看點

SpringBoot整合Spring Cloud Alibaba

spring-cloud官方中文文檔 ​​https://www.springcloud.cc/spring-cloud-dalston.html​​
spring-cloud官方文檔 ​​https://cloud.spring.io/spring-cloud-static/Greenwich.SR1/single/spring-cloud.html#_quick_start_6​​
Spring Cloud Alibaba官方文檔 ​​https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E​​

文章目錄

  • ​​1. SpringBoot整合Spring Cloud​​
  • ​​2. SpringBoot整合Spring Cloud Alibaba​​
  • ​​3. 為什麼SpringBoot整合Spring Cloud ?​​
  • ​​4. 為什麼SpringBoot 整合Spring Cloud Alibaba?​​
  • ​​5. 為什麼SpringBoot 整合SC和SCA分前後?​​
  • ​​6. 整合案例​​
  • ​​7. 整合完成後,驗證整合是否正确?​​
  • ​​8. 整合歸納​​

1. SpringBoot整合Spring Cloud

<dependencyManagement>
        <!--SpringBoot整合Spring Cloud-->
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Greenwich.SR1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>      

2. SpringBoot整合Spring Cloud Alibaba

<dependencyManagement>
        <!--SpringBoot整合Spring Cloud-->
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Greenwich.SR1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!--SpringBoot整合Spring Cloud Alibaba-->
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>2.1.0.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
      

3. 為什麼SpringBoot整合Spring Cloud ?

原因:如果想用Spring Cloud中的技術,需要指定版本,而Spring Cloud對子項目指定了版本,并做好了整合。

4. 為什麼SpringBoot 整合Spring Cloud Alibaba?

原因:如果想用Spring Cloud Alibaba中的技術,需要指定版本,而Spring Cloud Alibaba都對子項目指定了版本,并做好了整合。

5. 為什麼SpringBoot 整合SC和SCA分前後?

SpringBoot 整合Spring Cloud Alibaba要先整合Spring Cloud,因為Spring Cloud Alibaba屬于Spring Cloud的子項目,在Spring Cloud中對Spring Cloud Alibaba子項目指定了版本,并做了整合。

6. 整合案例

  • 例:

    SpringBoot整合Spring Cloud Alibaba中的nacos,隻需下面這樣寫即可,不需要指定版本号。

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>      
SpringBoot整合Spring Cloud Alibaba

7. 整合完成後,驗證整合是否正确?

mvn clean install      

8. 整合歸納

繼續閱讀