Spring Cloud Alibaba

Spring cloud Alibaba为分布式应用程序开发了一站式解决方案。它包含开发分布式应用程序所需的所有组件,使您轻松的地使用Spring Cloud开发应用程序。
再多的就不说了,官网https://spring.io/projects/spring-cloud-alibaba,有兴趣的可以看看。
本次需要用的技术组件:

  • Nacos:服务注册中心,跟Eureka功能类似,也可以做服务配置中心
  • Spring Cloud Ribbon:负载均衡工具
  • Feign:是一个声明式,模板化的HTTP客户端,可以做到用http请求远程服务就像调用本地方法,其内部包含了ribbon
  • Sentinel:流量控制,降级熔断。类似于Hystrix
  • Spring cloud stream & RabbitMQ:构建消息驱动的微服务应用程序框架
  • Spring Cloud Gateway:网关

    创建父工程

    创建父工程之前,注意一下版本问题。
    官方:
    https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E
    推荐:
Spring Cloud Version Spring Cloud Alibaba Version Spring boot Version
Spring Cloud Hoxton.SR3 2.2.1.RELEASE 2.2.5.RELEASE
Spring Cloud Hoxton.RELEASE 2.2.0.RELEASE 2.2.X.RELEASE
Spring Cloud Greenwich 2.1.2.RELEASE 2.1.X.RELEASE
Spring Cloud Finchley 2.0.2.RELEASE 2.0.X.RELEASE
Spring Cloud Edgware 1.5.1.RELEASE 1.5.X.RELEASE

这里使用的是Hoxton.SR3+2.2.1.RELEASE+2.2.5.RELEASE
创建父工程
使用Spring Cloud Alibaba创建springcloud项目-创建父工程 - 图1
使用Spring Cloud Alibaba创建springcloud项目-创建父工程 - 图2
pom.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5. <modelVersion>4.0.0</modelVersion>
  6. <groupId>com.study</groupId>
  7. <artifactId>cloudstudy</artifactId>
  8. <version>1.0-SNAPSHOT</version>
  9. <packaging>pom</packaging>
  10. <properties>
  11. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  12. <maven.compiler.source>1.8</maven.compiler.source>
  13. <maven.compiler.target>1.8</maven.compiler.target>
  14. <junit.version>4.12</junit.version>
  15. <log4j.version>1.2.17</log4j.version>
  16. <lombok.version>1.16.18</lombok.version>
  17. <mysql.version>5.1.47</mysql.version>
  18. <druid.version>1.1.16</druid.version>
  19. <mybatis.spring.boot.version>1.3.2</mybatis.spring.boot.version>
  20. </properties>
  21. <!-- 子模块继承之后,提供作用:锁定版本+子模块不用写groupId和version -->
  22. <dependencyManagement>
  23. <dependencies>
  24. <!-- springboot 2.2.5 -->
  25. <dependency>
  26. <groupId>org.springframework.boot</groupId>
  27. <artifactId>spring-boot-dependencies</artifactId>
  28. <version>2.2.5.RELEASE</version>
  29. <type>pom</type>
  30. <scope>import</scope>
  31. </dependency>
  32. <!-- springcloud cloud Hoxton.SR3 -->
  33. <dependency>
  34. <groupId>org.springframework.cloud</groupId>
  35. <artifactId>spring-cloud-dependencies</artifactId>
  36. <version>Hoxton.SR3</version>
  37. <type>pom</type>
  38. <scope>import</scope>
  39. </dependency>
  40. <!-- springcloud cloud alibaba 2.2.1.RELEASE -->
  41. <dependency>
  42. <groupId>com.alibaba.cloud</groupId>
  43. <artifactId>spring-cloud-alibaba-dependencies</artifactId>
  44. <version>2.2.1.RELEASE</version>
  45. <type>pom</type>
  46. <scope>import</scope>
  47. </dependency>
  48. <dependency>
  49. <groupId>mysql</groupId>
  50. <artifactId>mysql-connector-java</artifactId>
  51. <version>${mysql.version}</version>
  52. </dependency>
  53. <dependency>
  54. <groupId>com.alibaba</groupId>
  55. <artifactId>druid</artifactId>
  56. <version>${druid.version}</version>
  57. </dependency>
  58. <dependency>
  59. <groupId>org.mybatis.spring.boot</groupId>
  60. <artifactId>mybatis-spring-boot-starter</artifactId>
  61. <version>${mybatis.spring.boot.version}</version>
  62. </dependency>
  63. <dependency>
  64. <groupId>log4j</groupId>
  65. <artifactId>log4j</artifactId>
  66. <version>${log4j.version}</version>
  67. </dependency>
  68. <dependency>
  69. <groupId>junit</groupId>
  70. <artifactId>junit</artifactId>
  71. <version>${junit.version}</version>
  72. </dependency>
  73. <dependency>
  74. <groupId>org.projectlombok</groupId>
  75. <artifactId>lombok</artifactId>
  76. <version>${lombok.version}</version>
  77. <optional>true</optional>
  78. </dependency>
  79. </dependencies>
  80. </dependencyManagement>
  81. <build>
  82. <plugins>
  83. <plugin>
  84. <groupId>org.springframework.boot</groupId>
  85. <artifactId>spring-boot-maven-plugin</artifactId>
  86. <configuration>
  87. <fork>true</fork>
  88. <addResources>true</addResources>
  89. </configuration>
  90. </plugin>
  91. </plugins>
  92. </build>
  93. </project>

使用Spring Cloud Alibaba创建springcloud项目-2.搭建Nacos

参考文章:
使用Spring Cloud Alibaba创建springcloud项目-1.创建父工程