我服了!SpringBoot升级后这服务我一个星期都没跑起来!(上)
最近由于各方面的原因在准备升级 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依赖
这个提交把 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升级后这服务我一个星期都没跑起来!(上)的更多相关文章
- springboot 升级到2.0后 context-path 配置 不起作用,不生效 不管用 皆是因为版本改动导致的在这里记录一下
不知不觉,新的项目已经将springboot升级为2.0版本了.刚开始没有配置server.contextpath,默认的“/”,然后今天放到自己的服务器上,所以就要规范名称. 结果,失败了,无论我 ...
- springboot升级到2.0后context-path配置不起作用
springboot升级到2.0后,context-path配置不起作用,改成了: server.servlet.context-path=/projname
- 升级了Springboot版本后项目启动不了了
问题背景 项目上使用的springboot版本是2.1.1.RELEASE,现在因为要接入elasticsearch7.x版本,参考官方文档要求,需要将springboot版本升级到2.5.14. 本 ...
- Java Web项目如何做到升级不断掉服务,同时涉及到的相关问题
Java Web项目如何做到升级不断掉服务,同时涉及到的相关问题 原文地址:https://m.oschina.net/question/737237_2203576 现在容器用的是tomcat,做维 ...
- 【.net core】电商平台升级之微服务架构应用实战
一.前言 这篇文章本来是继续分享IdentityServer4 的相关文章,由于之前有博友问我关于微服务相关的问题,我就先跳过IdentityServer4的分享,进行微服务相关的技术学习和分享.微服 ...
- 关于kali2.0rolling中metasploit升级后无法启动问题的解决总结
最近在学习metasploit的使用,文中提到可以使用msfupdate命令来对metasploit的payload.exploit等进行升级,我就试了一下,没想到升级过程并不麻烦,但升级后却出现了无 ...
- 彻底解决phpcms v9升级后,文章发布出现: Mysql 1267错误:MySQL Error : Illegal mix of collations 解决办法
彻底解决phpcms v9升级后,文章发布出现: MySQL Query : SELECT * FROM `withli_a`.`v9_keyword` WHERE `keyword` = '吼吼' ...
- nodejs在同一台服务器上部署并同时运行两个或以上服务端时,一个服务用户登录后会挤掉另一个用户的问题
问题描述:一台服务器,部署了两个或以上不同的Web服务,服务A的用户在登陆后,服务B的用户也登陆,此时服务A的用户在点击页面时,会返回登陆页面. 问题根源:浏览器保存的session相同,即cooki ...
- 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 ...
随机推荐
- (最简单详细)IronPython下载、安装及简单使用
说实话,对于我这种小白,在网上找个IronPython找的很费劲,学会操作之后,直接整个随笔,供新手参考.前提是现在你应该有VS了 (1)找到IronPython的网站 很多人肯定就按照习惯搜索,Ir ...
- PostgreSQL 欺骗优化器之扩展统计信息
一.什么是扩展统计 扩展统计对象, 追踪指定表.外部表或物化视图的数据. 目前支持的种类: 启用n-distinct统计的 ndistinct. 启用功能依赖性统计的dependencies. 启用最 ...
- File类、FileOutputStream
day01 File类 File类的每一个实例可以表示硬盘(文件系统)中的一个文件或目录(实际上表示的是一个抽象路径) 使用File可以做到: 1:访问其表示的文件或目录的属性信息,例如:名字,大小, ...
- Java 热更新 Groovy 实践及踩坑指南
Groovy 是什么? Apache的Groovy是Java平台上设计的面向对象编程语言.这门动态语言拥有类似Python.Ruby和Smalltalk中的一些特性,可以作为Java平台的脚本语言使用 ...
- 使用C#编写一个.NET分析器(一)
译者注 这是在Datadog公司任职的Kevin Gosse大佬使用C#编写.NET分析器的系列文章之一,在国内只有很少很少的人了解和研究.NET分析器,它常被用于APM(应用性能诊断).IDE.诊断 ...
- WinUI 3 踩坑记:前言
WinUI 3 (Windows App SDK 于 2021 年 11 月发布了第一个正式版 v1.0.0 [1],最新版本是 v1.1.5 [2].我的基于 WinUI 3 的个人项目 寻空 从年 ...
- js工厂模式和构造函数
<!DOCTYPE html><html><head> <title>工厂模式和构造函数</title> <meta charset ...
- AlertManager 何时报警
转载自:https://www.qikqiak.com/post/alertmanager-when-alert/ 在使用 Prometheus 进行监控的时候,通过 AlertManager 来进行 ...
- TLS安全策略等级
TLS安全策略包含HTTPS可选的TLS协议版本和配套的加密算法套件.TLS协议版本越高,HTTPS通信的安全性越高,但是相较于低版本TLS协议,高版本TLS协议对浏览器的兼容性较差. ssl_cip ...
- 第一个Django应用 - 第四部分:表单和类视图
一.表单form 为了接收用户的投票选择,我们需要在前端页面显示一个投票界面.让我们重写先前的polls/detail.html文件,代码如下: <h1>{{ question.quest ...