毕业版本依赖关系(推荐使用)

由于 Spring Boot 3.0,Spring Boot 2.7~2.4 和 2.4 以下版本之间变化较大,目前企业级客户老项目相关 Spring Boot 版本仍停留在 Spring Boot 2.4 以下,为了同时满足存量用户和新用户不同需求,社区以 Spring Boot 3.0 和 2.4 分别为分界线,同时维护 2022.x、2021.x、2.2.x 三个分支迭代。如果不想跨分支升级,如需使用新特性,请升级为对应分支的新版本。 为了规避相关构建过程中的依赖冲突问题,我们建议可以通过 云原生应用脚手架 进行项目创建。

2022.x 分支

适配 Spring Boot 3.0,Spring Cloud 2022.x 版本及以上的 Spring Cloud Alibaba 版本按从新到旧排列如下表(最新版本用*标记): (注意,该分支 Spring Cloud Alibaba 版本命名方式进行了调整,未来将对应 Spring Cloud 版本,前三位为 Spring Cloud 版本,最后一位为扩展版本,比如适配 Spring Cloud 2022.0.0 版本对应的 Spring Cloud Alibaba 第一个版本为:2022.0.0.0,第个二版本为:2022.0.0.1,依此类推)

Spring Cloud Alibaba Version Spring Cloud Version Spring Boot Version
2022.0.0.0-RC* Spring Cloud 2022.0.0 3.0.0

2021.x 分支

适配 Spring Boot 2.4,Spring Cloud 2021.x 版本及以上的 Spring Cloud Alibaba 版本按从新到旧排列如下表(最新版本用*标记):

Spring Cloud Alibaba Version Spring Cloud Version Spring Boot Version
2021.0.5.0* Spring Cloud 2021.0.5 2.6.13
2021.0.4.0 Spring Cloud 2021.0.4 2.6.11
2021.0.1.0 Spring Cloud 2021.0.1 2.6.3
2021.1 Spring Cloud 2020.0.1 2.4.2

2.2.x 分支

适配 Spring Boot 为 2.4,Spring Cloud Hoxton 版本及以下的 Spring Cloud Alibaba 版本按从新到旧排列如下表(最新版本用*标记):

Spring Cloud Alibaba Version Spring Cloud Version Spring Boot Version
2.2.10-RC1* Spring Cloud Hoxton.SR12 2.3.12.RELEASE
2.2.9.RELEASE Spring Cloud Hoxton.SR12 2.3.12.RELEASE
2.2.8.RELEASE Spring Cloud Hoxton.SR12 2.3.12.RELEASE
2.2.7.RELEASE Spring Cloud Hoxton.SR12 2.3.12.RELEASE
2.2.6.RELEASE Spring Cloud Hoxton.SR9 2.3.2.RELEASE
2.2.1.RELEASE Spring Cloud Hoxton.SR3 2.2.5.RELEASE
2.2.0.RELEASE Spring Cloud Hoxton.RELEASE 2.2.X.RELEASE
2.1.4.RELEASE Spring Cloud Greenwich.SR6 2.1.13.RELEASE
2.1.2.RELEASE Spring Cloud Greenwich 2.1.X.RELEASE
2.0.4.RELEASE(停止维护,建议升级) Spring Cloud Finchley 2.0.X.RELEASE
1.5.1.RELEASE(停止维护,建议升级) Spring Cloud Edgware 1.5.X.RELEASE

组件版本关系

每个 Spring Cloud Alibaba 版本及其自身所适配的各组件对应版本如下表所示(注意,Spring Cloud Dubbo 从 2021.0.1.0 起已被移除出主干,不再随主干演进):

Spring Cloud Alibaba Version Sentinel Version Nacos Version RocketMQ Version Dubbo Version Seata Version
2021.0.5.0 1.8.6 2.2.0 4.9.4 ~ 1.6.1
2.2.10-RC1 1.8.6 2.2.0 4.9.4 ~ 1.6.1
2022.0.0.0-RC1 1.8.6 2.2.1-RC 4.9.4 ~ 1.6.1
2.2.9.RELEASE 1.8.5 2.1.0 4.9.4 ~ 1.5.2
2021.0.4.0 1.8.5 2.0.4 4.9.4 ~ 1.5.2
2.2.8.RELEASE 1.8.4 2.1.0 4.9.3 ~ 1.5.1
2021.0.1.0 1.8.3 1.4.2 4.9.2 ~ 1.4.2
2.2.7.RELEASE 1.8.1 2.0.3 4.6.1 2.7.13 1.3.0
2.2.6.RELEASE 1.8.1 1.4.2 4.4.0 2.7.8 1.3.0
2021.1 or 2.2.5.RELEASE or 2.1.4.RELEASE or 2.0.4.RELEASE 1.8.0 1.4.1 4.4.0 2.7.8 1.3.0
2.2.3.RELEASE or 2.1.3.RELEASE or 2.0.3.RELEASE 1.8.0 1.3.3 4.4.0 2.7.8 1.3.0
2.2.1.RELEASE or 2.1.2.RELEASE or 2.0.2.RELEASE 1.7.1 1.2.1 4.4.0 2.7.6 1.2.0
2.2.0.RELEASE 1.7.1 1.1.4 4.4.0 2.7.4.1 1.0.0
2.1.1.RELEASE or 2.0.1.RELEASE or 1.5.1.RELEASE 1.7.0 1.1.4 4.4.0 2.7.3 0.9.0
2.1.0.RELEASE or 2.0.0.RELEASE or 1.5.0.RELEASE 1.6.3 1.1.1 4.4.0 2.7.3 0.7.1
  • eg
    • envdata-service-nacos
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      yml
      cloud:
      nacos:
      server-addr: 127.0.0.1:8848

      pom
      <!-- nacos 配置管理 -->
      <dependency>
      <groupId>com.alibaba.cloud</groupId>
      <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
      <version>2.2.0.RELEASE</version>
      </dependency>
      <!-- nacos 服务发现 -->
      <dependency>
      <groupId>com.alibaba.cloud</groupId>
      <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
      <version>2.2.0.RELEASE</version>
      <exclusions>
      <exclusion>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
      </exclusion>
      </exclusions>
      </dependency>

      <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-loadbalancer</artifactId>
      <version>2.2.0.RELEASE</version>
      </dependency>

      bootstrap
      spring:
      application:
      name: baoju-intelligence-service
      profiles:
      active: dev-local
      cloud:
      nacos:
      server-addr: 127.0.0.1:8848
      config:
      file-extension: yaml

      // ---
      Application
      @EnableDiscoveryClient
      <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-commons</artifactId>
      <version>2.2.0.RELEASE</version>
      </dependency>
    • serial-num-parent
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      spring:
      application:
      name: serial-num-service
      cloud:
      nacos:
      server-addr: 127.0.0.1:8848

      <module>feign</module>

      parent
      <!-- spring cloud -->
      <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-dependencies</artifactId>
      <version>${spring.cloud-version}</version>
      <type>pom</type>
      <scope>import</scope>
      </dependency>

      <!-- nacos服务管理 -->
      <dependency>
      <groupId>com.alibaba.cloud</groupId>
      <artifactId>spring-cloud-alibaba-dependencies</artifactId>
      <version>${spring.cloud.alibaba-version}</version>
      <type>pom</type>
      <scope>import</scope>
      </dependency>

      service
      <!-- Nacos服务发现 -->
      <dependency>
      <groupId>com.alibaba.cloud</groupId>
      <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
      <version>2021.0.4.0</version>
      </dependency>
      <!-- nacos 配置管理 -->
      <dependency>
      <groupId>com.alibaba.cloud</groupId>
      <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
      <version>2021.0.4.0</version>
      </dependency>
      <!-- 读取bootstrap文件 -->
      <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-bootstrap</artifactId>
      <version>3.0.3</version>
      </dependency>

      bootstrap
      spring:
      application:
      name: serial-num-service
      profiles:
      active: dev-local
      cloud:
      nacos:
      server-addr: 127.0.0.1:8848
      config:
      file-extension: yaml

      //
      <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-dependencies</artifactId>
      <version>2021.0.4</version>
      <type>pom</type>
      <scope>import</scope>
      </dependency>
    • 模块调用
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      com
      └─glspkz
      └─serial
      └─feign
      ├─client
      └─pojo

      @RefreshScope
      SerialNumberCtrl

      @EnableFeignClients(clients = {SerialNumClient.class})
      Application(env)

      <!--feign依赖-->
      <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-openfeign</artifactId>
      <version>2.1.0.RELEASE</version>
      </dependency>

      @FeignClient("serial-num-service")
      public interface SerialNumClient {
      @GetMapping("/serial-num/{code}")
      R<SerialNum> getSerialNum(@PathVariable("code") String code);
      }
      SerialNumberCtrl.getSerialNum -> @PathVariable("code")
      // 在@PathVariable注解参数中注明路径参数名。feign会通过反射解析这些名称。

      @Data
      public class SerialNum {
      private String num;
      }
    • 内部调用
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      @RefreshScope
      SerialNumberCtrl

      @EnableFeignClients
      Applicaton(env)

      @FeignClient("serial-num-service")
      public interface SerialNumClient {
      @GetMapping("/serial-num/{code}")
      R<SerialNum> getSerialNum(@PathVariable String code);
      }

      <!-- feign依赖 -->
      <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-openfeign</artifactId>
      <version>2.2.0.RELEASE</version>
      </dependency>

      <!-- 调用feign -->
      <dependency>
      <groupId>com.glspkz</groupId>
      <artifactId>feign</artifactId>
      <version>1.0-SNAPSHOT</version>
      </dependency>

      <!-- httpclient 与Apache HttpClient冲突 -->
      <!-- <dependency>-->
      <!-- <groupId>io.github.openfeign</groupId>-->
      <!-- <artifactId>feign-httpclient</artifactId>-->
      <!-- <version>11.0</version>-->
      <!-- </dependency>-->

      @Data
      public class SerialNum {
      private String num;
      }

      @Autowired
      private SerialNumClient serialNumClient;

      @GetMapping("test")
      public String test() {
      R<SerialNum> serialNum = serialNumClient.getSerialNum("sampling_wo");
      String num = serialNum.getData().getNum();
      System.out.println(num);
      return num;
      }
    • gateway…
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72
      73
      74
      pom
      <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-autoconfigure</artifactId>
      </dependency>

      <!-- 网关 -->
      <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-gateway</artifactId>
      <version>3.1.0</version>
      </dependency>
      <!-- nacos服务发现依赖 -->
      <dependency>
      <groupId>com.alibaba.cloud</groupId>
      <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
      <version>2021.0.4.0</version>
      </dependency>

      @Order(-1) // 过滤器排序
      @Component
      public class AuthorizeFilter implements GlobalFilter {

      @Override
      public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {

      // 1.获取请求参数
      MultiValueMap<String, String> params = exchange.getRequest().getQueryParams();
      // 2.获取authorization参数
      String auth = params.getFirst("authorization");
      // 3.校验
      if ("admin".equals(auth)) { // authorization=admin
      // 放行
      return chain.filter(exchange);
      }
      // 4.拦截
      // 4.1.禁止访问,设置状态码
      exchange.getResponse().setStatusCode(HttpStatus.FORBIDDEN);
      // 4.2.结束处理
      return exchange.getResponse().setComplete();
      }
      }

      @SpringBootApplication
      public class GatewayApplication {
      public static void main(String[] args){
      SpringApplication.run(GatewayApplication.class,args);
      }
      }

      server:
      port: 10010
      spring:
      application:
      name: gateway
      cloud:
      nacos:
      server-addr: localhost:8848
      gateway:
      routes: # 网关路由配置
      - id: serial-num-service # 路由id,自定义,唯一即可
      # uri: http://127.0.0.1:8888 # 路由的目标地址 http是固定地址
      uri: lb://serial-num-service # 路由目标地址 后面跟服务名称
      predicates: # 路由断言,判断请求是否符合路由规则的条件
      - Path=/serial/** # 按照路径匹配
      - id: baoju-intelligence-service
      uri: lb://baoju-intelligence-service
      predicates:
      - Path=/env/**
      # default-filters: #默认过滤器
      # - AddRequestHeader=Truth,gabrielle is awesome
      logging:
      level:
      org.springframework.cloud.gateway: debug

官方版本说明

版本说明