由于以前没有使用过dubbo进行服务提供,我在项目里写了一个测试服务。各种配置正确,接口都是通的,服务也已经正确的在zookeeper上注册:
但是当我用测试项目去调用服务时仍然显示无服务提供者:
Caused by: java.lang.IllegalStateException: <b>Failed to check the status of the service com.wedoctor.health.card.cloud.user.share.service.MyService. No provider available for the service com.wedoctor.health.card.cloud.user.share.service.MyService</b> from the url zookeeper://192.168.100.109:2183/com.alibaba.dubbo.registry.RegistryService?application=HelloDubbo_ref&dubbo=2.8.4&interface=com.wedoctor.health.card.cloud.user.share.service.MyService&methods=add,multi&pid=12076&side=consumer&timeout=8000×tamp=1499912239905 to the consumer 192.168.100.16 use dubbo version 2.8.4
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
在重复多次检查配置和代码无误,并且网上搜索N久无果后,终于发现问题所在:
公司项目的Jetty在运行时配置了JVM参数:
-Ddubbo.service.group=longtao
该参数指定了提供服务的组,非该组的消费者无法访问!
解决办法两种:
测试项目运行时加上消费者组的参数:
<b>-Ddubbo.consumer.group=longtao</b>消费者xml配置文件中指定组:
<dubbo:reference id="myService" interface="com.wedoctor.health.card.cloud.user.share.service.MyService" timeout="8000" group="longtao"/>
ps:引起该错误的原因可能有很多种,具体网上查询