dubbo 消费者启动报错 Failed to check the status of the service

记录使用dubbo时的报错

1. 报错信息

Failed to check the status of the service cn.qiuming.dubbo.api.DubboService. No provider available for the service

Caused by: java.lang.IllegalStateException: Failed to check the status of the service cn.qiuming.dubbo.api.DubboService. No provider available for the service cn.qiuming.dubbo.api.DubboService from the url spring-cloud://192.168.1.7:9090/org.apache.dubbo.registry.RegistryService?application=seata-one&dubbo=2.0.2&interface=cn.qiuming.dubbo.api.DubboService&lazy=false&methods=serviceOneError,serviceTwoError,success&pid=2440&qos.enable=false®ister.ip=192.168.1.7&release=2.7.3&side=consumer&sticky=false×tamp=1627551353909 to the consumer 192.168.1.7 use dubbo version 2.7.3
	at org.apache.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:418) ~[dubbo-2.7.3.jar:2.7.3]
	at org.apache.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:329) ~[dubbo-2.7.3.jar:2.7.3]
	at org.apache.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:250) ~[dubbo-2.7.3.jar:2.7.3]
	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor$ReferenceBeanInvocationHandler.init(ReferenceAnnotationBeanPostProcessor.java:269) ~[dubbo-2.7.3.jar:2.7.3]
	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor$ReferenceBeanInvocationHandler.access$100(ReferenceAnnotationBeanPostProcessor.java:242) ~[dubbo-2.7.3.jar:2.7.3]
	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.buildInvocationHandler(ReferenceAnnotationBeanPostProcessor.java:236) ~[dubbo-2.7.3.jar:2.7.3]
	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.buildProxy(ReferenceAnnotationBeanPostProcessor.java:219) ~[dubbo-2.7.3.jar:2.7.3]
	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.doGetInjectedBean(ReferenceAnnotationBeanPostProcessor.java:134) ~[dubbo-2.7.3.jar:2.7.3]
	at org.apache.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor.getInjectedObject(AnnotationInjectedBeanPostProcessor.java:360) ~[dubbo-2.7.3.jar:2.7.3]
	at org.apache.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor$AnnotatedFieldElement.inject(AnnotationInjectedBeanPostProcessor.java:540) ~[dubbo-2.7.3.jar:2.7.3]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE]
	at org.apache.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor.postProcessPropertyValues(AnnotationInjectedBeanPostProcessor.java:147) ~[dubbo-2.7.3.jar:2.7.3]
	... 30 common frames omitted

2. 解决过程

该错误是dubbo的消费者在启动时,找不到其对应的提供者,原因有下

  1. 因为在计算机安装了VMware或其他类型的虚拟机,而造成提供者或者在启动时使用了虚拟网卡

    在这里插入图片描述

    观察框中的ip信息和该机的ipv4地址 是否能对应上 cmd ipconfig

    解决方案: 在网络与安全中禁用掉其他用不上的网卡驱动

  2. 打开提供者的微服务代码,比对 application.yml文件的dubbo.scan.base-packages 与 api接口,及其接口实现类,观察接口和实现类在扫描包的目录下面(两者皆需要!)

    dubbo 消费者启动报错 Failed to check the status of the service_第1张图片

    可以看到实现类的包和api接口都在cn.qiuming.dubbo.api的路径下,若实现类不在该路径下也会报错

3. 事后猜想

  1. 消费者在启动时, 会扫描包下的@org.apache.dubbo.config.annotation.Reference注解
  2. 消费者启动时会预先尝试连接扫描的接口,看是否能ping成功,成功才能正常启动消费者微服务
  3. 消费者携带该注解下的api接口(名字或其他识别信息), 根据yml中的配置 dubbo.cloud.subscribed-services去注册中心nacos中寻找订阅的提供者微服务
  4. 提供者需要进行响应,提供者在启动时会根据yml配置的dubbo.scan.base-packages去扫描api接口及其实现,注册dubbo到nacos中
  5. 消费者在请求提供者时,若是接口不存在,或者接口未被实现,都会造成响应失败,从而终止消费者的启动

你可能感兴趣的:(dubbo,java)