dubbo2.x升级到dubbo3
Dubbo3 基于 Dubbo2 演进而来,在保持原有核心功能特性的同时, Dubbo3 在易用性、超大规模微服务实践、云原生基础设施适配等几大方向上进行了全面升级按官方文档,直接修改版本号,将原来的2.7.9 改为 3.0.1<dependency><groupId>org.apache.dubbo</groupId><artifactId>dub
Dubbo3 基于 Dubbo2 演进而来,在保持原有核心功能特性的同时, Dubbo3 在易用性、超大规模微服务实践、云原生基础设施适配等几大方向上进行了全面升级
最重要的是:支持多语言,能够和GRPC,HTTP服务互通
按官方文档,直接修改版本号,将原来的2.7.9 改为 3.0.1
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<dubbo.version>3.0.1</dubbo.version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<dubbo.version>3.0.1</dubbo.version>
</dependency>
启动服务报错:
[2021-08-09 17:34:01.491] [ERROR] [ main] [o.s.b.d.LoggingFailureAnalysisReporter ] [TID: N/A]:
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
com.alibaba.nacos.spring.core.env.NacosPropertySourcePostProcessor.postProcessBeanFactory(NacosPropertySourcePostProcessor.java:91)
The following method did not exist:
com.alibaba.spring.util.BeanUtils.getBeanNames(Lorg/springframework/beans/factory/config/ConfigurableListableBeanFactory;Ljava/lang/Class;)[Ljava/lang/String;
The method's class, com.alibaba.spring.util.BeanUtils, is available from the following locations:
jar:file:/C:/Users/DDZX/.m2/repository/com/alibaba/spring/spring-context-support/1.0.8/spring-context-support-1.0.8.jar!/com/alibaba/spring/util/BeanUtils.class
The class hierarchy was loaded from the following locations:
com.alibaba.spring.util.BeanUtils: file:/C:/Users/DDZX/.m2/repository/com/alibaba/spring/spring-context-support/1.0.8/spring-context-support-1.0.8.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of com.alibaba.spring.util.BeanUtils
Process finished with exit code 1
从上面可以看出,是com/alibaba/spring/spring-context-support/1.0.8/spring-context-support-1.0.8.jar 这个包版本有问题
解决:
升级spring-context-support版本到1.0.11,即添加以下依赖再次启动,成功了
<dependency>
<groupId>com.alibaba.spring</groupId>
<artifactId>spring-context-support</artifactId>
<version>1.0.11</version>
</dependency>
成功后在nacos注册中心就看到应用级注册和接口级注册同时存在
等全部升级为应用级后配置
dubbo.application.service-discovery.migration=APPLICATION_FIRST
YML格式需要改写成:
dubbo:
# 配置服务信息
application:
#可选值 interface、instance、all,默认是 interface,即只注册接口级地址
register-mode: all
#只消费应用级
service-discovery:
# FORCE_INTERFACE,只消费接口级地址,如无地址则报错,单订阅 2.x 地址
# APPLICATION_FIRST,智能决策接口级/应用级地址,双订阅
# FORCE_APPLICATION,只消费应用级地址,如无地址则报错,单订阅 3.x 地址
migration: APPLICATION_FIRST
这样配置之后消费者就只消费3.x的地址
如果依赖了3.0.0 ,启动可能还会出现如下错误
[2021-08-09 19:02:26.192] [ERROR] [ main] [o.s.boot.SpringApplication ] [TID: N/A] : Application run failed
java.lang.NullPointerException: null
at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.isAnnotatedReferenceBean(ReferenceAnnotationBeanPostProcessor.java:165)
at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.postProcessBeanFactory(ReferenceAnnotationBeanPostProcessor.java:131)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:291)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:175)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:707)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:533)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at com.dadaodata.other.OtherApplication.main(OtherApplication.java:24)
解决办法:就是依赖3.0.1版本就可以了,3.0.0版本有一些bug
再次踩坑
在引用dubbo服务的时候如果后面添加了check=false,比如下面写法,启动就会报错:
@DubboReference(check = false)
private OrderService orderService;
报错内容:
[2021-08-09 19:47:05.278] [ERROR] [ main] [o.s.boot.SpringApplication ] [TID:N/A] : Application run failed
org.springframework.beans.factory.BeanCreationException: Already exists another reference bean with the same bean name and type but difference attributes. In order to avoid injection confusion, please modify the name of one of the beans: prev: orderService[ReferenceBean:com.dadaodata.other.api.order.OrderService()], new: orderService[ReferenceBean:com.dadaodata.other.api.order.OrderService(check=false)]. Please check private com.dadaodata.other.api.order.OrderService com.dadaodata.miaopi.controller.user.ParentController.orderService
at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.registerReferenceBean(ReferenceAnnotationBeanPostProcessor.java:394)
at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.prepareInjection(ReferenceAnnotationBeanPostProcessor.java:317)
at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.postProcessBeanFactory(ReferenceAnnotationBeanPostProcessor.java:149)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:291)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:175)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:707)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:533)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at com.dadaodata.miaopi.MiaopiApplication.main(MiaopiApplication.java:16)
解决办法:删除check = false:
@DubboReference(check = false)
private OrderService orderService;
修改为:
@DubboReference
private OrderService orderService;
该bug在dubbo官方也有讨论:https://github.com/apache/dubbo/issues/8145
备注
应用级地址调用没有成功,即用下面的配置请求接口时会报错,提示没有找到provider:
register-mode: instance
service-discovery:
migration: FORCE_APPLICATION
具体请求异常:
No provider available from registry 192.168.0.22:8080 for service com.test.user.api.manager.studentService on consumer 172.23.112.1 use dubbo version 3.0.1, please check status of providers(disabled, not registered or in blacklist).
总之:双订阅方式验证通过,应用级的还不行,不知道是哪一步出现问题还是dubbo 本身bug导致
升级指南参考:https://dubbo.apache.org/zh/docs/migration/migration-and-compatibility-guide/
更多推荐
所有评论(0)