dubbo異常:Failed to check the status of the service . No provider available for the service 解決

服務消費者調用報Failed to check the status of the service . No provider available for the service 這個問題 ,dubboadmin上邊看服務正常啓動 ,報錯信息如下:
在這裏插入圖片描述

Exception in thread “main” org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘demoService’: FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: Failed to check the status of the service com.alibaba.dubbo.demo.DemoService. No provider available for the service com.alibaba.dubbo.demo.DemoService from the url zookeeper://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?application=demo-consumer&dubbo=2.5.3&interface=com.alibaba.dubbo.demo.DemoService&methods=sayHello&pid=98896&side=consumer&timestamp=1565446380941 to the consumer 192.168.0.107 use dubbo version 2.5.3
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:178)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:101)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1647)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getObjectForBeanInstance(AbstractAutowireCapableBeanFactory.java:1215)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:257)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1085)
at com.alibaba.dubbo.demo.Consumer.main(Consumer.java:10)
Caused by: java.lang.IllegalStateException: Failed to check the status of the service com.alibaba.dubbo.demo.DemoService. No provider available for the service com.alibaba.dubbo.demo.DemoService from the url zookeeper://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?application=demo-consumer&dubbo=2.5.3&interface=com.alibaba.dubbo.demo.DemoService&methods=sayHello&pid=98896&side=consumer&timestamp=1565446380941 to the consumer 192.168.0.107 use dubbo version 2.5.3
at com.alibaba.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:420)
at com.alibaba.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:300)
at com.alibaba.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:138)
at com.alibaba.dubbo.config.spring.ReferenceBean.getObject(ReferenceBean.java:65)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:171)
… 7 more

Process finished with exit code 1
問題解析:
可能出錯的地方:
1、
提供者的XML配置如下:

<!--聲明需要暴露的服務接口 version是服務的版本號dubbo只找對應版本號的服務提供者進行調用 timeout 超時時間 超過時間過報錯-->
<dubbo:service interface="com.alibaba.dubbo.demo.DemoService" ref="demoService" version="1.0" timeout="5000"/>

消費者的XML配置:

<dubbo:reference id="demoService"  interface="com.alibaba.dubbo.demo.DemoService" version="1.0"/>

經過反覆查找原因終於鎖定了生產者XML和消費者文件中的version=“1.0”

教訓:如果生產者設定了服務的版本,消費者一定要提供相應的版本號;
如果生產者不設定了服務的版本,消費者一定不設置版本號;
兩者必須保持一致;
2、如果pom.xml中dubbo去掉了spring的配置
pom.xml中加入spring-context對應的jar包
3、在網上有的說可能與服務提供者的@Service引入的jar包有關,經過本人測試,如果是使用xml的配置
加不加@Service這個註解不影響正常調用,即使加了@service註解,引入import org.springframework.stereotype.Service;或者import com.alibaba.dubbo.config.annotation.Service;不影響,都可以正常調用;
另外重寫的方法加不加@Override註解也不影響

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章