在dubbo与zookeeper的简单案例中,成功启动provider应用,由于粘贴粗心,在启动consumer应用的时候蹦出一个ERROR
java.lang.reflect.InvocationTargetException: null
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_241]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_241]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_241]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_241]
at com.alibaba.dubbo.config.AbstractConfig.toString(AbstractConfig.java:474) ~[dubbo-2.6.2.jar:2.6.2]
...
Failed to check the status of the service...
...
No provider available for the service...
...
不愿意看记录,可以直接翻到文末找解决办法
调用异常?
于是四处查找,找注解,没问题;找yml配置没问题;找服务器上zookeeper的配置,找aliyun安全组配置,都没问题。找了老长时间,天已经很晚了
第二天才认真去看ERROR后的正常log,log真的很长,一大溜,头天晚上并没有认真往后翻。于是看到以下日志
在consumer应用的相关log是:
c.a.d.r.zookeeper.ZookeeperRegistry : [DUBBO] Register: consumer://192.168.43.100/com.icourage.consumeruser.service.TicketService
和
c.a.d.r.zookeeper.ZookeeperRegistry : [DUBBO] Subscribe: consumer://192.168.43.100/com.icourage.consumeruser.service.TicketService
也就是register和subscribe的是com.icourage.consumeruser.service.TicketService
在provider应用的相关log是:
c.a.d.r.zookeeper.ZookeeperRegistry : [DUBBO] Register: dubbo://192.168.43.100:12398/com.icourage.providerticket.service.TicketService
和
c.a.d.r.zookeeper.ZookeeperRegistry : [DUBBO] Subscribe: provider://192.168.43.100:12398/com.icourage.providerticket.service.TicketService
register和subscribe的是com.icourage.providerticket.service.TicketService
notify的URL:
c.a.d.r.zookeeper.ZookeeperRegistry : [DUBBO] Notify urls for subscribe url provider://192.168.43.100:12398/com.icourage.providerticket.service.TicketService
provider应用启动类上的 @EnableDubbo 注解会扫描与启动类同级的包及其子包(与Spring..扫描范围相同)是否有 @com.alibaba.dubbo.config.annotation.Service 标识的类,注册的接口是该类的全路径【package name.class name】
consumer应用则会以 @Reference 的接口 refer
resources
从上面可以看到是consumer应用中,interface TicketService 所在包有问题,应该是 com.icourage.providerticket.service,所以
PS:保持好的分包、编码习惯他不香吗
dubbo zookeeper Failed to check the status of the service...No provider available for the service
原文:https://www.cnblogs.com/Ycourage/p/12676020.html