dubbo服务调用异常:No provider available for the service

1. 异常描述

在启动基于spring boot的order-consumer项目时,报错:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-09-19 16:14:34.167 ERROR 2615 --- [           main] o.s.boot.SpringApplication               : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderController' defined in file [/Users/cypher02/workspace/gitee/high-concurrency/order/order-consumer/target/classes/cn/lilyssh/order/consumer/controller/OrderController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderService' defined in file [/Users/cypher02/workspace/gitee/high-concurrency/order/order-consumer/target/classes/cn/lilyssh/order/consumer/service/OrderService.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: orderService; nested exception is java.lang.IllegalStateException: Failed to check the status of the service cn.lilyssh.goods.api.service.GoodsServiceApi. No provider available for the service cn.lilyssh.goods.api.service.GoodsServiceApi from the url zookeeper://ssh.qianxunclub.com:2181/com.alibaba.dubbo.registry.RegistryService?application=order-consumer&dubbo=2.6.0&interface=cn.lilyssh.goods.api.service.GoodsServiceApi&methods=exist,saveBatch,save,list,updateById&pid=2615&register.ip=192.168.31.31&side=consumer&timestamp=1537344873982 to the consumer 192.168.31.31 use dubbo version 2.6.0
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:732) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:197) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1267) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1124) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:330) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at cn.lilyssh.order.consumer.OrderConsumerApplication.main(OrderConsumerApplication.java:12) [classes/:na]
Disconnected from the target VM, address: '127.0.0.1:56417', transport: 'socket'
Process finished with exit code 1

2. 异常分析

No provider available for the service cn.lilyssh.goods.api.service.GoodsServiceApi
从异常的信息看,有两种可能:

  1. 在zookeeper里没注册进去服务
  2. 注册进去了,但是拿不出来。
    进去zookeeper里看看就知道怎么肥四了:
ls  /dubbo/cn.lilyssh.order.api.service.OrderServiceApi/providers
dubbo://192.168.31.31:3333/cn.lilyssh.order.api.service.OrderServiceApi?anyhost=true&application=order-provider&default.timeout=5000&dubbo=2.6.0&generic=false&interface=cn.lilyssh.order.api.service.OrderServiceApi&methods=saveBatch,save,list&pid=2541&revision=1.2.3&side=provider&timestamp=1537344229809&version=1.2.3

最后是 version=1.2.3
原来是往外抛服务时,加了版本号:

@Slf4j
@Service(version = "1.2.3")
@Component
@AllArgsConstructor
public class GoodsService implements GoodsServiceApi {

}

而在order-coonsumer项目中,引用时,却没加版本号

@Slf4j
@Component
public class OrderService {

    @Reference
    private GoodsServiceApi goodsServiceApi;

    @Reference(version = "1.2.3")
    private OrderServiceApi orderServiceApi;
}

3. 解决办法

注册和调用的服务的版本号要一致!

大功告成!

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值