Dubbo報錯:no provider available for the service

在整合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] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'doctorController': Injection of @org.apache.dubbo.config.annotation.Reference dependencies is failed; nested exception is java.lang.IllegalStateException: Failed to check the status of the service com.quliankeji.medicalcloud.iservice.doctor.IDoctorSV. No provider available for the service medicalcloud/com.quliankeji.medicalcloud.iservice.doctor.IDoctorSV from the url zookeeper://127.0.0.1:2181/org.apache.dubbo.registry.RegistryService?application=medicalcloud-consumer&default.timeout=20000&dubbo=2.0.2&group=medicalcloud&interface=com.quliankeji.medicalcloud.iservice.doctor.IDoctorSV&methods=getDoctorByCondition,getDoctorDetail&pid=1208&qos.enable=false&register.ip=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 org.apache.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor.postProcessPropertyValues(AnnotationInjectedBeanPostProcessor.java:132)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1416)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:849)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
	at com.quliankeji.medicalcloud.portal.PortalApplication.main(PortalApplication.java:16)
Caused by: java.lang.IllegalStateException: Failed to check the status of the service com.quliankeji.medicalcloud.iservice.doctor.IDoctorSV. No provider available for the service medicalcloud/com.quliankeji.medicalcloud.iservice.doctor.IDoctorSV from the url zookeeper://127.0.0.1:2181/org.apache.dubbo.registry.RegistryService?application=medicalcloud-consumer&default.timeout=20000&dubbo=2.0.2&group=medicalcloud&interface=com.quliankeji.medicalcloud.iservice.doctor.IDoctorSV&methods=getDoctorByCondition,getDoctorDetail&pid=1208&qos.enable=false&register.ip=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 org.apache.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:393)
	at org.apache.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:301)
	at org.apache.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:225)
	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor$ReferenceBeanInvocationHandler.init(ReferenceAnnotationBeanPostProcessor.java:162)
	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor$ReferenceBeanInvocationHandler.access$100(ReferenceAnnotationBeanPostProcessor.java:146)
	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.buildInvocationHandler(ReferenceAnnotationBeanPostProcessor.java:140)
	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.buildProxy(ReferenceAnnotationBeanPostProcessor.java:122)
	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.doGetInjectedBean(ReferenceAnnotationBeanPostProcessor.java:116)
	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.doGetInjectedBean(ReferenceAnnotationBeanPostProcessor.java:49)
	at org.apache.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor.getInjectedObject(AnnotationInjectedBeanPostProcessor.java:340)
	at org.apache.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor$AnnotatedFieldElement.inject(AnnotationInjectedBeanPostProcessor.java:520)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90)
	at org.apache.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor.postProcessPropertyValues(AnnotationInjectedBeanPostProcessor.java:128)
	... 17 common frames omitted


選擇重要的信息進行觀察,Failed to check the status of the service com.quliankeji.medicalcloud.iservice.doctor.IDoctorSV,這裏的意思就是這個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="com.taotao.ItemService" check="false" />
  1. 關閉所有服務的啓動時檢查,
<dubbo:consumer check="false" />
  1. 關閉註冊中心啓動時檢查:(註冊訂閱失敗時報錯)
<dubbo:registry check="false" />
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章