Dubbo报错:no provider available for the service

时间:2025-02-18 08:56:56

在整合dubbo开发项目的时候,服务端能正常启动,启动web端的时候,控制台报错:no provider available for the service
这是个比较头疼的问题,控制台报错如下

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-05-25 11:37:47.560 ERROR 1208 --- [           main]                : Application run failed

: Error creating bean with name 'doctorController': Injection of @ dependencies is failed; nested exception is : Failed to check the status of the service . No provider available for the service medicalcloud/ from the url zookeeper://127.0.0.1:2181/?application=medicalcloud-consumer&=20000&dubbo=2.0.2&group=medicalcloud&interface=&methods=getDoctorByCondition,getDoctorDetail&pid=1208&=false&=192.168.0.103&release=2.7.0&side=consumer&timestamp=1558755467501 to the consumer 192.168.0.103 use dubbo version 2.7.0
	at (:132)
	at (:1416)
	at (:592)
	at (:515)
	at $doGetBean$0(:320)
	at (:222)
	at (:318)
	at (:199)
	at (:849)
	at (:877)
	at (:549)
	at (:142)
	at (:775)
	at (:397)
	at (:316)
	at (:1260)
	at (:1248)
	at (:16)
Caused by: : Failed to check the status of the service . No provider available for the service medicalcloud/ from the url zookeeper://127.0.0.1:2181/?application=medicalcloud-consumer&=20000&dubbo=2.0.2&group=medicalcloud&interface=&methods=getDoctorByCondition,getDoctorDetail&pid=1208&=false&=192.168.0.103&release=2.7.0&side=consumer&timestamp=1558755467501 to the consumer 192.168.0.103 use dubbo version 2.7.0
	at (:393)
	at (:301)
	at (:225)
	at $(:162)
	at $$100(:146)
	at (:140)
	at (:122)
	at (:116)
	at (:49)
	at (:340)
	at $(:520)
	at (:90)
	at (:128)
	... 17 common frames omitted


选择重要的信息进行观察,Failed to check the status of the service ,这里的意思就是这个Service接口创建失败,
后面的异常信息非常重要:No provider available for the service ,意思就是对于service来说,没有可实现的provider
消费者在访问提供者的时候失败了。

解决方案

Dubbo默认(缺省)会在启动时检查依赖的服务是否可用,不可用时会抛出异常,阻止Spring初始化完成,以便上线时,能及早发现问题,默认check=true
如果你的Spring容器是懒加载的,或者通过API编程延迟引用服务,请关闭check,否则服务临时不可用时,会抛出异常,拿到null引用,如果check=false,总是会返回引用,当服务恢复时,能自动连上。
可以通过check=”false”关闭检查,比如,测试时,有些服务不关心,或者出现了循环依赖,必须有一方先启动。

  1. 关闭某个服务的启动时检查
<dubbo:reference interface="" check="false" />
  1. 关闭所有服务的启动时检查,
<dubbo:consumer check="false" />
  1. 关闭注册中心启动时检查:(注册订阅失败时报错)
<dubbo:registry check="false" />