dubbo2.x升级到dubbo3

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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据您提供的引用内容,配置`dubbo.protocols.dubbo.port=-1`可以开启Dubbo端口的随机分配功能。这样配置后,Dubbo将自动选择一个可用的端口进行通信。 另外,要查看Dubbo进程的端口,可以使用`lsof -i | grep dubbo进程ID | grep LISTEN`命令。该命令会列出所有使用Dubbo协议的进程的信息,包括监听的端口。 关于Dubbo管理平台,您可以下载dubbo-admin.2.5.6.war包并部署自己的服务器上。您提到有一些免积分下载的方法,但是目前最低要求是2个积分。 最后,针对您提到的问题描述`Failed to bind properties under 'spring.dubbo.application' to com.alibaba.dubbo.config.ApplicationConfig: Property: spring.dubbo.application.logger Value: Slf4j Origin: class path resource [application.properties]:17:33 Reason: No such extension com.alibaba.dubbo.common.logger.LoggerAdapter by name Slf4j`,根据这个描述,看起来是在应用配置中使用了`spring.dubbo.application.logger`这个属性,但是`com.alibaba.dubbo.common.logger.LoggerAdapter`扩展中没有名为`Slf4j`的实现[3]。这可能是由于配置文件中的错误或者版本不匹配导致的。您可以检查配置文件中的属性是否正确,或者尝试更新Dubbo的版本来解决该问题。 总结起来,配置`dubbo.protocols.dubbo.port=-1`可以开启Dubbo端口的随机分配功能。您可以使用命令`lsof -i | grep dubbo进程ID | grep LISTEN`来查看Dubbo进程的端口。另外,您可以下载dubbo-admin.2.5.6.war包并部署自己的服务器上来使用Dubbo管理平台。对于问题描述中的错误,建议检查配置文件中的属性是否正确或者尝试更新Dubbo的版本。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值