org.springframework.beans.factory.BeanCreationException: Error creating bean with name解决方案

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘tenantController’: Injection of @org.apache.dubbo.config.annotation.Reference dependencies is failed; nested exception is java.lang.IllegalStateException: Failed to check the status of the service com.len.pdms.service.TenantService. No provider available for the service com.len.pdms.service.TenantService from the url zookeeper://127.0.0.1:2181/

或者Caused by: java.lang.IllegalStateException: Failed to check the status of the service com.len.pdms.service.TenantService. No provider available for the service com.len.pdms.service.TenantService from the url zookeeper://127.0.0.1:2181/org.apache.dubbo.registry.RegistryService

具体问题如下:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tenantController': Injection of @org.apache.dubbo.config.annotation.Reference dependencies is failed; nested exception is java.lang.IllegalStateException: Failed to check the status of the service com.len.pdms.service.TenantService. No provider available for the service com.len.pdms.service.TenantService from the url zookeeper://127.0.0.1:2181/org.apache.dubbo.registry.RegistryService?anyhost=true&application=pdms-consumer&bean.name=ServiceBean:com.len.pdms.service.TenantService&check=false&default=false&dubbo=2.0.2&generic=false&group=&interface=com.len.pdms.service.TenantService&logger=slf4j&methods=existsWithPrimaryKey,select,insertUseGeneratedKeys,selectByIds,addTenant,updateByPrimaryKeySelective,show,insert,delete,showAll,updateByExample,selectByPrimaryKey,selectByExampleAndRowBounds,selectListByPage,updateByExampleSelective,getList,updateByPrimaryKey,selectByExample,insertSelective,insertList,selectOneByExample,selectAll,selectOne,deleteByExample,selectByRowBounds,selectCount,selectCountByExample,deleteByPrimaryKey,deleteByIds&pid=10452&qos.enable=false&register.ip=192.168.1.11&release=2.7.0&remote.application=pdms-provider&remote.timestamp=1584504156891&side=consumer&timestamp=1584505110654 to the consumer 192.168.1.11 use dubbo version 2.7.0
	at org.apache.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor.postProcessPropertyValues(AnnotationInjectedBeanPostProcessor.java:132) ~[dubbo-2.7.0.jar:2.7.0]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1344) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:578) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
	at com.len.Application.main(Application.java:38) [classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_65]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_65]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_65]
	at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_65]
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.0.1.RELEASE.jar:2.0.1.RELEASE]
Caused by: java.lang.IllegalStateException: Failed to check the status of the service com.len.pdms.service.TenantService. No provider available for the service com.len.pdms.service.TenantService from the url zookeeper://127.0.0.1:2181/org.apache.dubbo.registry.RegistryService?anyhost=true&application=pdms-consumer&bean.name=ServiceBean:com.len.pdms.service.TenantService&check=false&default=false&dubbo=2.0.2&generic=false&group=&interface=com.len.pdms.service.TenantService&logger=slf4j&methods=existsWithPrimaryKey,select,insertUseGeneratedKeys,selectByIds,addTenant,updateByPrimaryKeySelective,show,insert,delete,showAll,updateByExample,selectByPrimaryKey,selectByExampleAndRowBounds,selectListByPage,updateByExampleSelective,getList,updateByPrimaryKey,selectByExample,insertSelective,insertList,selectOneByExample,selectAll,selectOne,deleteByExample,selectByRowBounds,selectCount,selectCountByExample,deleteByPrimaryKey,deleteByIds&pid=10452&qos.enable=false&register.ip=192.168.1.11&release=2.7.0&remote.application=pdms-provider&remote.timestamp=1584504156891&side=consumer&timestamp=1584505110654 to the consumer 192.168.1.11 use dubbo version 2.7.0
	at org.apache.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:393) ~[dubbo-2.7.0.jar:2.7.0]
	at org.apache.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:301) ~[dubbo-2.7.0.jar:2.7.0]
	at org.apache.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:225) ~[dubbo-2.7.0.jar:2.7.0]
	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor$ReferenceBeanInvocationHandler.init(ReferenceAnnotationBeanPostProcessor.java:162) ~[dubbo-2.7.0.jar:2.7.0]
	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor$ReferenceBeanInvocationHandler.access$100(ReferenceAnnotationBeanPostProcessor.java:146) ~[dubbo-2.7.0.jar:2.7.0]
	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.buildInvocationHandler(ReferenceAnnotationBeanPostProcessor.java:140) ~[dubbo-2.7.0.jar:2.7.0]
	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.buildProxy(ReferenceAnnotationBeanPostProcessor.java:122) ~[dubbo-2.7.0.jar:2.7.0]
	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.doGetInjectedBean(ReferenceAnnotationBeanPostProcessor.java:116) ~[dubbo-2.7.0.jar:2.7.0]
	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.doGetInjectedBean(ReferenceAnnotationBeanPostProcessor.java:49) ~[dubbo-2.7.0.jar:2.7.0]
	at org.apache.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor.getInjectedObject(AnnotationInjectedBeanPostProcessor.java:340) ~[dubbo-2.7.0.jar:2.7.0]
	at org.apache.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor$AnnotatedFieldElement.inject(AnnotationInjectedBeanPostProcessor.java:520) ~[dubbo-2.7.0.jar:2.7.0]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.apache.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor.postProcessPropertyValues(AnnotationInjectedBeanPostProcessor.java:128) ~[dubbo-2.7.0.jar:2.7.0]
	... 22 common frames omitted

解决方案:

  1. 方案一:
    这种错误是服务层代码没有成功注册到注册中心导致,请检查一下你的服务层代码是否添加了@service注解,并且该注解的包一定是com.alibaba.dubbo.config.annotation包,不是org.springframework.stereotype.Service,这个地方容易出错。
  2. 方案二:
    检查分布式服务提供者和消费者的 .yml 文件中的注册中心地址是否正确
dubbo:
  registry:
    address: zookeeper://127.0.0.1:2181  #zookeeper注册中心地址
  1. 方案三:
    检查调用的接口路径是否错误,在参数中 interface=com.len.pdms.service.TenantService,而com.len.pdms.service.TenantService就是要远程调用的接口,检查远程或第三发服务提供商(也就是提供者)接口包路径是否与消费者一致(必须保证一致)。
  2. 方案四:
    如果以上问题都没有的话,那么很有可能是你的分布式服务提供者没有开启,只是打开了消费者服务。也就是说我们在运行的时候需要同时开启两个Application服务。第一次玩这个没有注意 ╥﹏╥
    two application
    finally:
    dubbo
发布了35 篇原创文章 · 获赞 2 · 访问量 4408

猜你喜欢

转载自blog.csdn.net/weixin_41072132/article/details/104941900
今日推荐