最近由于各方面的原因在准备升级 Spring Cloud 和 Spring Boot,经过一系列前置的调研和分析,决定把Spring Boot 相关版本从 2.1.6 升级到 2.7.5,Spring Cloud 相关版本从 Greenwich.SR1 升级为 2021.0.4。

升级包含基础的业务服务代码的升级改造适配,还有就是中间件一堆代码的改造,上周经历了一周的修改,用来测试的服务仍然还没有跑起来,所以这篇文章我会记录下来这升级过程中的一些问题,由于革命仍未成功,所以这是上篇。

1. hibernate-validator包下的类报错

在 Spring Boot 2.3版本之后,spring-boot-starter-web 中没有依赖 hibernate-validator。

解决方案:使用新的依赖。

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

2. ApplicationEnvironmentPreparedEvent类改变

Spring Boot 2.4版本之后,ApplicationEnvironmentPreparedEvent 构造函数新增了ConfigurableBootstrapContext,业务代码还好,应该都用不上这个类,中间件代码使用到的地方都需要修改。

解决方案:修改代码。

public ApplicationEnvironmentPreparedEvent(ConfigurableBootstrapContext bootstrapContext,
SpringApplication application, String[] args, ConfigurableEnvironment environment) {
super(application, args);
this.bootstrapContext = bootstrapContext;
this.environment = environment;
}

3. junit依赖升级

升级后的junit版本默认是junit5(我没有去确认是哪个版本发生了变化),升级之后包名发生了改变,所有的测试用例都需要修改。

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

另外发现Assert类不存在了,可以改用Assertions

Assertions.assertNotNull(result);

解决方案:修改代码!

4. Spring Cloud兼容问题

由于测试过程中先升级的 Spring Boot,发现 Spring Cloud 使用到的低版本代码不兼容,升级到文章开头说的版本之后问题解决。

比如下面的 spring-cloud-context 启动时候报错。

5. SpringApplicationRunListener类改变

和第二个问题比较类似,SpringApplicationRunListener 中这两个方法新增了 ConfigurableBootstrapContext,对应实现类都需要修改,这个应该无论在业务还是中间件代码中都应该有大量的使用。

解决方案:修改代码!

default void starting(ConfigurableBootstrapContext bootstrapContext) {}
default void environmentPrepared(ConfigurableBootstrapContext bootstrapContext,ConfigurableEnvironment environment) {}

6. ServerProperties变更

spring-boot-autoconfigure 包下 ServerProperties 中的内部类 Tomcat 属性变更,获取最大线程数方法发生改变。

原写法:serverProperties.getTomcat().getMaxThreads()

解决方案:serverProperties.getTomcat().getThreads().getMax()

7. spring-cloud-openfeign中移除ribbon和hystrix依赖

Commit地址:https://github.com/spring-cloud/spring-cloud-openfeign/commit/8a08e1ec4b4f0d40193a4ea9c03afdeffe3110a6

这个提交把 spring-cloud-openfeign 里面关于 ribbon 和 hystrix 的依赖相关代码全部删除了,这个 commit 我找了一遍 issue 和 PR,都没有发现相关说明,大佬直接删的,具体原因不清楚为什么直接全删干净了。

比如我的启动报错:

Caused by: java.lang.ClassNotFoundException: org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient

解决方案:手动引入新的依赖。

 <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
<version>2.2.10.RELEASE</version>
</dependency>

8. bootstrap.properties/yml 配置文件不生效

根据 Spring Cloud 配置方式,发现很多业务的本地配置配置在 bootstrap.properties中,新版本默认会不生效。

老版本中 spring.cloud.bootstrap.enabled 默认为 true。

新版本改过之后默认是false了,导致一堆配置不生效。

解决方案:手动设置spring.cloud.bootstrap.enabled=true

9. spring-cloud-netflix-eureka-client中移除ribbon和hystrix依赖

和第七个问题差不多,spring-cloud-netflix-eureka-client 移除了 ribbon和hystrix依赖,所以客户端默认不会有ribbon这些东西了。

解决方案:手动引入新的依赖。

 <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
<version>2.2.10.RELEASE</version>
</dependency>

10. spring-cloud-starter-alibaba-sentinel版本不兼容

spring-cloud-starter-alibaba-sentinel 使用的是 2.1.3.RELEASE ,和新版本存在兼容性问题,导致无法启动,存在循环依赖问题。

报错信息:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration': Unsatisfied dependency expressed through method 'setConfigurers' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.alibaba.cloud.sentinel.SentinelWebAutoConfiguration': Unsatisfied dependency expressed through field 'sentinelWebInterceptorOptional'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'com.alibaba.cloud.sentinel.SentinelWebAutoConfiguration': Requested bean is currently in creation: Is there an unresolvable circular reference?

解决方案:升级为当前 Spring Cloud 一样的版本。

 <dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
<version>2021.0.4.0</version>
</dependency>

11. commons-pool2兼容性报错

spring-boot-autoconfigure 2.7.5版本中 JedisConnectionConfiguration 报错,原因在于我们有的业务代码依赖中自己指定了 commons-pool2的版本。

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.autoconfigure.data.redis.JedisConnectionConfiguration.jedisPoolConfig(JedisConnectionConfiguration.java:114) The following method did not exist: redis.clients.jedis.JedisPoolConfig.setMaxWait(Ljava/time/Duration;)V Action: Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.boot.autoconfigure.data.redis.JedisConnectionConfiguration and redis.clients.jedis.JedisPoolConfig

Git Issue :https://github.com/spring-projects/spring-boot/issues/27642

看这个时间很早就修正了,commons-pool2 在2.8.1版本后丢失了一些方法。

解决方案:自己不要指定该包版本默认会使用 spring boot 的最新依赖,或者手动指定最新版本2.11.1。

12. 循环依赖报错

spring-boot 2.6版本之后禁止循环依赖,有的话启动会报错,报错信息和第十个问题是一样的,不同的是业务代码的报错而已。

解决方案:手动解决代码循环依赖问题或者设置属性 spring.main.allow-circular-references=true

13. spring-rabbit 版本兼容

升级之后,由于中间件封装了 rabbit 的一些功能,去掉了 spring-rabbit的自动装配,导致基本上整个中间件包不可用,大量方法不兼容。

解决方案:全部用2.7.5版本的代码覆盖自动装配的逻辑。

小总结

看起来这些问题都只是一两句话的功夫,但是实际上花了大量的时间在排查、找解决方案,还有把所有现在依赖的包版本重新筛查,修改包版本、重新打包测试版本,中间非人体验实在不是一两句话能说清楚的,我觉得,做业务开发其实也挺好的。

目前革命还只是进行了一小步,还有更多的问题需要去解决,不过这个星期必须全部解决!!!

我服了!SpringBoot升级后这服务我一个星期都没跑起来!(上)的更多相关文章

  1. springboot 升级到2.0后 context-path 配置 不起作用,不生效 不管用 皆是因为版本改动导致的在这里记录一下

    不知不觉,新的项目已经将springboot升级为2.0版本了.刚开始没有配置server.contextpath,默认的“/”,然后今天放到自己的服务器上,所以就要规范名称.  结果,失败了,无论我 ...

  2. springboot升级到2.0后context-path配置不起作用

    springboot升级到2.0后,context-path配置不起作用,改成了: server.servlet.context-path=/projname

  3. 升级了Springboot版本后项目启动不了了

    问题背景 项目上使用的springboot版本是2.1.1.RELEASE,现在因为要接入elasticsearch7.x版本,参考官方文档要求,需要将springboot版本升级到2.5.14. 本 ...

  4. Java Web项目如何做到升级不断掉服务,同时涉及到的相关问题

    Java Web项目如何做到升级不断掉服务,同时涉及到的相关问题 原文地址:https://m.oschina.net/question/737237_2203576 现在容器用的是tomcat,做维 ...

  5. 【.net core】电商平台升级之微服务架构应用实战

    一.前言 这篇文章本来是继续分享IdentityServer4 的相关文章,由于之前有博友问我关于微服务相关的问题,我就先跳过IdentityServer4的分享,进行微服务相关的技术学习和分享.微服 ...

  6. 关于kali2.0rolling中metasploit升级后无法启动问题的解决总结

    最近在学习metasploit的使用,文中提到可以使用msfupdate命令来对metasploit的payload.exploit等进行升级,我就试了一下,没想到升级过程并不麻烦,但升级后却出现了无 ...

  7. 彻底解决phpcms v9升级后,文章发布出现: Mysql 1267错误:MySQL Error : Illegal mix of collations 解决办法

    彻底解决phpcms v9升级后,文章发布出现: MySQL Query : SELECT * FROM `withli_a`.`v9_keyword` WHERE `keyword` = '吼吼' ...

  8. nodejs在同一台服务器上部署并同时运行两个或以上服务端时,一个服务用户登录后会挤掉另一个用户的问题

    问题描述:一台服务器,部署了两个或以上不同的Web服务,服务A的用户在登陆后,服务B的用户也登陆,此时服务A的用户在点击页面时,会返回登陆页面. 问题根源:浏览器保存的session相同,即cooki ...

  9. centos 7 升级后yum install出现Exiting on user cancel

    centos 7 升级后yum install出现Exiting on user cancel centos 7.x升级后用yum install进行安装时经常出现Exiting on user ca ...

随机推荐

  1. 算法模板:spfa

    #include<iostream> #include<algorithm> #include<cstring> #include<string> #i ...

  2. P4035 [JSOI2008]球形空间产生器 (向量,高斯消元)

    题面 有一个 n n n 维球,给定 n + 1 n+1 n+1 个在球面上的点,求球心坐标. n ≤ 10 n\leq 10 n≤10 . 题解 好久以前的题了,昨天首 A . n n n 太小了! ...

  3. Codeforces Round #585 (Div. 2) E. Marbles (状压DP),BZOJ大理石(同一道题)题解

    题意 林老师是一位大理石收藏家,他在家里收藏了n块各种颜色的大理石,第i块大理石的颜色为ai.但是林老师觉得这些石头在家里随意摆放太过凌乱,他希望把所有颜色相同的石头放在一起.换句话说,林老师需要对现 ...

  4. HCNP Routing&Switching之MAC地址防漂移

    前文我们了解了二层端口安全技术相关话题,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/16631222.html:今天我们来聊一聊MAC地址防漂移技术: 首先我 ...

  5. 「题解报告」SP16185 Mining your own business

    题解 SP16185 Mining your own business 原题传送门 题意 给你一个无向图,求至少安装多少个太平井,才能使不管那个点封闭,其他点都可以与有太平井的点联通. 题解 其他题解 ...

  6. iOS 组件化及二进制化的探索

    组件化的优缺点 组件化的拆分 组件与组件之间如何进行通讯(路由) 从Cocopods拉取代码的过程 远程索引库里很多的.spec文件,该文件记录了很多内容,如用户名,框架名称,描述,框架的地址 Pod ...

  7. cnblogs-theme-blogure

    cnblogs-theme-blogure 又一个博客园主题 Blogure. 它使用 PetiteVue 和 PicoCSS. 喜欢的话可以帮个点 Star 么? 快速开始 确保博客园有 JS 权限 ...

  8. 查看pod对应的DNS域名

    单个pod # kubectl exec redis-pod-0 -n cluster-redis -- hostname -f redis-pod-0.redis-cluster-service.c ...

  9. 谣言检测(GACL)《Rumor Detection on Social Media with Graph Adversarial Contrastive Learning》

    论文信息 论文标题:Rumor Detection on Social Media with Graph AdversarialContrastive Learning论文作者:Tiening Sun ...

  10. POJ3280 Cheapest Palindrome (区间DP)

    dp[i][j]表示将字符串子区间[i,j]转化为回文字符串的最小成本. 1 #include<cstdio> 2 #include<algorithm> 3 #include ...