更新時(shí)間:2021-09-07 11:05:04 來(lái)源:動(dòng)力節(jié)點(diǎn) 瀏覽1870次
網(wǎng)上有很多類似問(wèn)題,場(chǎng)景為Dubbo服務(wù)端通過(guò)監(jiān)控中心查看是正常注冊(cè)了的,但是消費(fèi)者卻執(zhí)行時(shí)報(bào)錯(cuò),說(shuō)找不到服務(wù)提供者。異常如下圖所示:
log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
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.unj.dubbotest.provider.DemoService. No provider available for the service com.unj.dubbotest.provider.DemoService from the url zookeeper://localhost:2181/com.alibaba.dubbo.registry.RegistryService?anyhost=true&application=consumer-of-helloworld-app&check=false&dubbo=2.5.3&interface=com.unj.dubbotest.provider.DemoService&loadbalance=roundrobin&methods=sayHello&pid=108320&side=consumer×tamp=1500875956242 to the consumer 192.168.0.101 use dubbo version 2.5.3
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:175)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1634)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:254)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1078)
at Consumer.main(Consumer.java:11)
Caused by: java.lang.IllegalStateException: Failed to check the status of the service com.unj.dubbotest.provider.DemoService. No provider available for the service com.unj.dubbotest.provider.DemoService from the url zookeeper://localhost:2181/com.alibaba.dubbo.registry.RegistryService?anyhost=true&application=consumer-of-helloworld-app&check=false&dubbo=2.5.3&interface=com.unj.dubbotest.provider.DemoService&loadbalance=roundrobin&methods=sayHello&pid=108320&side=consumer×tamp=1500875956242 to the consumer 192.168.0.101 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:168)
... 6 more
一般由于以下前3種原因,這邊是因?yàn)榈?種,這里一一列舉出來(lái):
1.防火墻問(wèn)題:可以通過(guò)telnet嘗試連接服務(wù)端提供服務(wù)的地址加端口,看是否能夠正常連接。不行可能需要關(guān)閉防火墻,或配置開(kāi)放端口(大神操作)
2.注冊(cè)使用的網(wǎng)段ip錯(cuò)誤:一般是由于系統(tǒng)有多個(gè)ip,結(jié)果使用了一個(gè)與消費(fèi)者不通的ip進(jìn)行注冊(cè),可以在監(jiān)控中心查看注冊(cè)的url是什么ip,如下圖所示,這邊使用的192.168.0.101的內(nèi)部ip,是通的。
如果的確是ip的問(wèn)題,那么可以通過(guò)修改配置文件,在服務(wù)端的dubbo:protocol節(jié)點(diǎn)配置服務(wù)開(kāi)放端口時(shí),同時(shí)指定服務(wù)提供ip。這里消費(fèi)者端好像也可以配置host,我覺(jué)得意義不大,這里沒(méi)有試過(guò)。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!-- 提供方應(yīng)用信息,用于計(jì)算依賴關(guān)系 -->
<dubbo:application name="hello-world-app" />
<!-- 使用multicast廣播注冊(cè)中心暴露服務(wù)地址 -->
<!-- <dubbo:registry address="multicast://224.5.6.7:1234?unicast=false" />-->
<!-- zookeeper服務(wù)注冊(cè)中心 -->
<dubbo:registry address="zookeeper://localhost:2181" check="true" />
<!-- 用dubbo協(xié)議在20880端口暴露服務(wù) -->
<dubbo:protocol name="dubbo" host="192.168.0.101" port="20882" />
<!-- 聲明需要暴露的服務(wù)接口 -->
<dubbo:service interface="com.alibaba.dubbo.demo.DemoService" ref="demoService" version="1.0"/>
<!-- 和本地bean一樣實(shí)現(xiàn)服務(wù) -->
<bean id="demoService" class="com.alibaba.dubbo.demo.provider.DemoServiceImpl" />
</beans>
3.版本號(hào)問(wèn)題如上圖所示,服務(wù)端在dubbo:service的節(jié)點(diǎn)下配置了版本1.0,那么客戶端也需要在對(duì)應(yīng)的dubbo:reference節(jié)點(diǎn)下配置對(duì)應(yīng)版本號(hào),否則也是會(huì)報(bào)上面錯(cuò)誤的。筆者最開(kāi)始遇到的問(wèn)題不是前面三種的任何一種,但是發(fā)現(xiàn)第4點(diǎn)的問(wèn)題后發(fā)現(xiàn)還是不行,進(jìn)而基于網(wǎng)上有的幾個(gè)原因進(jìn)行排查,結(jié)果發(fā)現(xiàn)是之前按照網(wǎng)上說(shuō)的配了下版本號(hào),但是最終沒(méi)有保持一致。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!-- 消費(fèi)方應(yīng)用名,用于計(jì)算依賴關(guān)系,不是匹配條件,不要與提供方一樣 -->
<dubbo:application name="consumer-of-helloworld-app" />
<!-- 使用multicast廣播注冊(cè)中心暴露發(fā)現(xiàn)服務(wù)地址 -->
<!-- <dubbo:registry address="multicast://224.5.6.7:1234?unicast=false" /> -->
<dubbo:registry address="zookeeper://localhost:2181"/>
<!-- <dubbo:protocol host="192.168.0.101" /> -->
<!-- 生成遠(yuǎn)程服務(wù)代理,可以和本地bean一樣使用demoService -->
<dubbo:reference id="demoService" interface="com.alibaba.dubbo.demo.DemoService" version="1.0"/>
<!-- add by liuming to avoid reference 3rd party components -->
</beans>
4.依賴組件沒(méi)有引用全。通過(guò)使用網(wǎng)上現(xiàn)有的demo,我發(fā)現(xiàn)居然可以,然后與我自己搭的環(huán)境進(jìn)行對(duì)比。最終發(fā)現(xiàn)消費(fèi)者這端我忘記添加netty依賴組件了~~。這里要注意的是,缺少netty組件依賴報(bào)錯(cuò)和找不到服是一樣的,所以很難辨認(rèn)原因,缺少其他組件可能也有此現(xiàn)象。這點(diǎn)就要進(jìn)行仔細(xì)排查了。最后吐槽下,缺少netty組件不應(yīng)該報(bào)類找不到異常嗎?這個(gè)估計(jì)是把異常catch重新拋了一個(gè)新異常,把真實(shí)原因隱藏了,感覺(jué)有些不易維護(hù),這里用的2.5.3版本,不知道后面有沒(méi)有優(yōu)化。
以上就是動(dòng)力節(jié)點(diǎn)小編介紹的"Dubbo消費(fèi)者找不到服務(wù)提供者問(wèn)題",希望對(duì)大家有幫助,想了解更多可查看Dubbo教程。動(dòng)力節(jié)點(diǎn)在線學(xué)習(xí)教程,針對(duì)沒(méi)有任何Java基礎(chǔ)的讀者學(xué)習(xí),讓你從入門(mén)到精通,主要介紹了一些Java基礎(chǔ)的核心知識(shí),讓同學(xué)們更好更方便的學(xué)習(xí)和了解Java編程,感興趣的同學(xué)可以關(guān)注一下。
0基礎(chǔ) 0學(xué)費(fèi) 15天面授
有基礎(chǔ) 直達(dá)就業(yè)
業(yè)余時(shí)間 高薪轉(zhuǎn)行
工作1~3年,加薪神器
工作3~5年,晉升架構(gòu)
提交申請(qǐng)后,顧問(wèn)老師會(huì)電話與您溝通安排學(xué)習(xí)
初級(jí) 202925
初級(jí) 203221
初級(jí) 202629
初級(jí) 203743