应用升级 SpringCloud 版本时的注意事项 (Dalston 升级到 Edgware)

欢迎访问我的 GitHub
这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos
手里有个 Spring Cloud 的工程,是服务提供者的身份,在 pom.xml 中配置的 Spring Cloud 版本是 Dalston.SR5,要升级到 Edgware.RELEASE,有一处依赖包的改动需要注意;
升级前的配置
pom.xml 中和 Spring Cloud 相关的配置如下图所示,红框中是当前版本,绿框中是服务注册相关的 starter 依赖:

升级 Spring Cloud 版本
第一步:将版本号改为 Edgware.RELEASE 如下图:

第二步:将依赖包中的 spring-cloud-starter-eureka 改为 spring-cloud-starter-netflix-eureka-client,如下图:

为什么要用 spring-cloud-starter-netflix-eureka-client?
用 spring-cloud-starter-netflix-eureka-client 替代 spring-cloud-starter-eureka 的原因,来自以下几方面信息:
Maven 中央仓库,地址是:https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-eureka-server ,上面注明了 spring-cloud-starter-eureka-server 已经废弃,建议使用 spring-cloud-starter-netflix-eureka-server,如下图:

Dalston.SR5 版本的 Spring Cloud,对应的 spring-cloud-netflix 库是 1.3.6.RELEASE 版本,其官方文档中建议我们使用 spring-cloud-starter-eureka,文档地址:https://cloud.spring.io/spring-cloud-static/spring-cloud-netflix/1.3.6.RELEASE/multi/multi__service_discovery_eureka_clients.html#netflix-eureka-client-starter ,如下图:

Edgware.RELEASE 版本的 Spring Cloud,对应的 spring-cloud-netflix 库是 1.4.0.RELEASE 版本,其官方文档中建议我们使用 spring-cloud-starter-netflix-eureka-client,文档地址:https://cloud.spring.io/spring-cloud-netflix/1.4.x/multi/multi__service_discovery_eureka_clients.html ,如下图:

为了有更直观的认识,我们去看下官方示例 spring-cloud-samples/customers-stores,其中有从 Dalston.BUILD-SNAPSHOT 升级到 Finchley.SR1 的修改记录,地址是:https://github.com/spring-cloud-samples/customers-stores/commit/79f736fcc13562c14464a4b2b0025d3006c316ad ,如下图所示,红框代表删除行,绿框代表新增行:

最全面的信息来自官方的版本发布信息,地址是:https://github.com/spring-projects/spring-cloud/wiki/Spring-Cloud-Edgware-Release-Notes ,其他需要修改的依赖模块 ID 也都在列表中,如下图:

小结:官方文档和 demo 是最可靠的信息来源,涉及到升级操作时,最好把关键项列出来,去官方文档中确认一下;
欢迎关注 InfoQ:程序员欣宸
版权声明: 本文为 InfoQ 作者【程序员欣宸】的原创文章。
原文链接:【http://xie.infoq.cn/article/6e278996ee46731c44dd989d2】。文章转载请联系作者。
评论