本文经作者授权转载,原文作者:HD Superman,原文链接:Spring Gateway 版本依赖关系
背景
某天后台日志系统报 Spring Gateway 大量错误,其中很多报错如下:
io.netty.channel.AbstractChannel$AnnotatedConnectException: finishConnect(..) failed: Connection refused
由于最近后台系统整体往 JDK11 升级,很多工程都是直接 copy 过去,或者直接新建项目目录进行迁移,初步怀疑是版本问题。
定位到 Spring Gateway 工程上 maven 很多依赖没有标版本,google 查到的大部分错误也提到版本冲突问题。初步怀疑是版本冲突问题,进一步定位。
Spring Gateway 用到了下面几个关键包:
- spring-boot-starter-parent
- spring-cloud
- spring-cloud-starter-gateway
- spring-cloud-alibaba
- spring-cloud-starter-alibaba-nacos-config
怀疑相关包依赖冲突,导致 Bug 出现,后来查了相关依赖关系,修改版本号后 Bug 消除。下面总结下相关版本的依赖关系,避免后续项目迁移、升级再次出现类似问题。
Spring Boot 与 Spring Cloud 版本依赖关系
官方信息:start.spring.io/actuator/in… 链接打开为 json 格式没有格式化,可以用 firefox 打开,显示如下图:
Spring Boot 与 Spring Cloud Alibaba 版本依赖关系
组件版本关系
| Spring Cloud Alibaba Version | Sentinel Version | Nacos Version | RocketMQ Version | Dubbo Version | Seata Version |
|---|---|---|---|---|---|
| 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 |
毕业版本依赖关系(推荐使用)
| 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 |
以上述 Bug 为例子,项目主要用的Spring Boot 版本为:2.2.5.RELEASE
- 对应查到 Spring Cloud 使用的版本应该为:
Hoxton.SR3系列版本 - 对应查到 Spring Cloud Alibaba 应该使用使用:
2.2.1.RELEASE - 对应查到 Nacos 应该使用
1.2.1版本