从永远到永远-微服务框架升级

1 背景

为应对总部安全漏洞扫描,需要对项目框架进行升级

2 升级

2.1 概述

项目框架SpringBoot(下简称boot)基于2.3.2.RELEASE,鉴于3.x版本与2.x版本差异较大,升级成本太高。最终决定,将boot版本升级到2.7版本,Spring Cloud(下简称cloud)、SpringCloud Alibaba(下简称alibaba)版本,根据boot版本调整。

2.2 版本升级清单

jar包名称升级前版本升级后版本
boot2.3.2.RELEASE2.7.12
cloudHoxton.SR72021.0.7
alibaba2.2.3.RELEASE2021.0.5.0

2.3 升级问题

2.3.1 spring-cloud-starter-bootstrap

No spring.config.import property has been defined

Action:

Add a spring.config.import=nacos: property to your configuration.
	If configuration is not required add spring.config.import=optional:nacos: instead.
	To disable this check, set spring.cloud.nacos.config.import-check.enabled=false.

引入

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bootstrap</artifactId>
        </dependency>

2.3.2 commons-pool2

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.LettuceConnectionConfiguration$PoolBuilderFactory.getPoolConfig(LettuceConnectionConfiguration.java:188)

The following method did not exist:

    org.apache.commons.pool2.impl.GenericObjectPoolConfig.setMaxWait(Ljava/time/Duration;)

版本冲突,去掉commons-pool2依赖。参考

2.3.3 java: 程序包feign.hystrix不存在

import feign.hystrix.FallbackFactory;变成
import org.springframework.cloud.openfeign.FallbackFactory;

2.3.4 spring-cloud-loadbalancer

No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer?

Feign在Hoxton.M2 RELEASED版本之后,负载均衡不再使用Ribbon,而是使用spring-cloud-loadbalancer,所以不引入spring-cloud-loadbalancer会报错。

2.3.5 循环依赖(有时间进一步验证)

The dependencies of some of the beans in the application context form a cycle:
┌──->──┐
|  com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration
└──<-──┘

排除冲突依赖,或者升高版本

<!--			<exclusions>-->
<!--				<exclusion>-->
<!--					<groupId>org.mybatis</groupId>-->
<!--					<artifactId>mybatis</artifactId>-->
<!--				</exclusion>-->
<!--				<exclusion>-->
<!--					<groupId>org.mybatis</groupId>-->
<!--					<artifactId>mybatis-spring</artifactId>-->
<!--				</exclusion>-->
<!--			</exclusions>-->

參考1
參考2
參考3

2.3.6 springfox-swagger2

Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException

参考

2.3.7 sleuth版本冲突

.org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'traceFeignObjectWrapper' defined in class path resource [org/springframework/cloud/sleuth/instrument/web/client/feign/TraceFeignClientAutoConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.sleuth.instrument.web.client.feign.TraceFeignObjectWrapper] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:597) ~[spring-beans-5.3.27.jar:5.3.27]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.27.jar:5.3.27]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.27.jar:5.3.27]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.27.jar:5.3.27]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.27.jar:5.3.27]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.27.jar:5.3.27]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955) ~[spring-beans-5.3.27.jar:5.3.27]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:920) ~[spring-context-5.3.27.jar:5.3.27]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.27.jar:5.3.27]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.12.jar:2.7.12]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731) [spring-boot-2.7.12.jar:2.7.12]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) [spring-boot-2.7.12.jar:2.7.12]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-2.7.12.jar:2.7.12]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303) [spring-boot-2.7.12.jar:2.7.12]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292) [spring-boot-2.7.12.jar:2.7.12]
	at com.xxxx.data.RobotApplication.main(RobotApplication.java:18) [classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.7.12.jar:2.7.12]
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.sleuth.instrument.web.client.feign.TraceFeignObjectWrapper] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:485) ~[spring-core-5.3.27.jar:5.3.27]
	at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321) ~[spring-core-5.3.27.jar:5.3.27]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.buildLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:232) ~[spring-beans-5.3.27.jar:5.3.27]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.findLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:210) ~[spring-beans-5.3.27.jar:5.3.27]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(InitDestroyAnnotationBeanPostProcessor.java:149) ~[spring-beans-5.3.27.jar:5.3.27]
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(CommonAnnotationBeanPostProcessor.java:305) ~[spring-context-5.3.27.jar:5.3.27]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:1116) ~[spring-beans-5.3.27.jar:5.3.27]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.3.27.jar:5.3.27]
	... 20 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/springframework/cloud/openfeign/ribbon/CachingSpringLoadBalancerFactory
	at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_181]
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_181]
	at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_181]
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:467) ~[spring-core-5.3.27.jar:5.3.27]
	... 27 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.cloud.openfeign.ribbon.CachingSpringLoadBalancerFactory
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_181]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_181]
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) ~[na:1.8.0_181]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_181]
	... 31 common frames omitted
去掉版本,直接继承cloud的版本

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-sleuth</artifactId>
            <!--<version>2.2.4.RELEASE</version>-->
        </dependency>

2.3.8 网关及其他服务可以正常注册到nacos,但是无法转发请求

参考
貌似不需要禁用ribbon的支持也可以,待有时间进一步验证

2.3.9 vue前端项目起不来

参考1
参考2
不是专业前端,通过参考的连接处理的。这个问题,最开始怀疑是node版本的问题,更换过多次node版本。最后根据网络上大神们的解释,来回卸载安装依赖。其实本质上,是依赖没有成功下载下来。这里,如果不成,建议上梯子,看个github文档,也不卡了。

2.3.10 nacos

NacosException: user not found

参考
注意层级,和config、discovery同级别

2.3.11 xxl-job漏洞

参考

2.3.12 nacos-server(2.2.3)源码包内部的boot漏洞

需要手动,修改nacos源码打包
参考1
参考2
参考3

2.3.13 gateway配置

java: 找不到符号
  符号:   方法 hystrix((h)->h.set[...]ack"))
  位置:org.springframework.cloud.gateway.route.builder.GatewayFilterSpec

参考
yml的断言配置,去掉hystrix部分的

2.3.14 gateway配置

Caused by: java.lang.IllegalArgumentException: Unable to find GatewayFilterFactory with name Hystrix

具体咋解决的忘记了,去掉hystrix应该就好了吧,有时间进一步验证

2.3.15 nacos、负载均衡

2023-09-05 15:27:30.124 ERROR 3824 --- [           main] c.a.c.n.c.NacosPropertySourceBuilder     : get data from Nacos error,dataId:xxxx

com.alibaba.nacos.api.exception.NacosException: http error, code=403,msg=user not found!,dataId=xxx-gateway,group=DEFAULT_GROUP,tenant=

看似是nacos的问题,实际出在负载均衡上,去掉ribbon,引入loadbalancer依赖就好了

2.3.16 nacos-client被单独排除

java.lang.NoClassDefFoundError: com/alibaba/nacos/client/logging/NacosLogging

确保spring-cloud-starter-alibaba-nacos-discovery与spring cloud版本一致,检查是否是否引入了nacos-client依赖。
我升级的版本spring-cloud-starter-alibaba-nacos-discovery已经包含(nacos-client)
但是之前代码,是排除nacos-client,单独引入的。我把exclusives内容复制过来,不小心排掉了nacos-client,结果报错,不排除即可。

2.3.17 控制台打印停止,不报错,不继续执行

2023-09-06 08:58:48.040  INFO 47604 --- [oundedElastic-1] c.a.n.p.a.s.c.ClientAuthPluginManager    : [ClientAuthPluginManager] Load ClientAuthService com.alibaba.nacos.client.auth.impl.NacosClientAuthServiceImpl success.
2023-09-06 08:58:48.040  INFO 47604 --- [oundedElastic-1] c.a.n.p.a.s.c.ClientAuthPluginManager    : [ClientAuthPluginManager] Load ClientAuthService com.alibaba.nacos.client.auth.ram.RamClientAuthServiceImpl success.
 locator:
    enabled: true
如果开启会导致这个问题

参考1
参考2

2.3.18 fein客户端重名

The bean 'FeignClientSpecification' could not be registered. A bean with that name has already been defined and overriding is disabled.

contextIId区分

2.3.19 数据库已经配置,但不生效

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:

不生效是因为druid数据源再次扫描了数据库,排掉
参考

2.3.20 数据库已经配置,报错

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

检查MySQL数据库连接的时区等信息

2.3.21 gayteway中调用其他服务的feign接口报错

java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-3
	at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:83) ~[reactor-core-3.4.29.jar:3.4.29]
	Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Error has been observed at the following site(s):
	*__checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
	*__checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain]
	*__checkpoint ⇢ HTTP GET "/api/.....?username=admin" [ExceptionHandlingWebHandler]

一般离开说,网关应该是没有这样的调用的。升级后版本的cloud自带的gateway是基于webflux编程实习,不支持同步调用,改为异步调用即可。

2.3.22 循环依赖

目前版本不支持,自动处理循环依赖。Spring认为出现循环依赖,是代码写得不合理,不再支持自动处理。检查代码,能改则改,不能改@Lazy手动处理

3.相关

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值