问题概述

关于这儿问题是在微服务开发过程中遇到的,通过本地远程调用dubbo接口,用xml实例化bean时报 “ No bean named 'tDubboServiceImpl' is defined ”。

部分截图如下:

具体内容如下:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.huazai.b2c.aiyou.service.TDubboService': Cannot resolve reference to bean 'tDubboServiceImpl' while setting bean property 'ref'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'tDubboServiceImpl' is definedat org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1481)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)at java.util.concurrent.FutureTask.run(FutureTask.java:266)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'tDubboServiceImpl' is definedat org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:698)at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1175)at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284)at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)... 24 more

解决办法

在一个程序接口中,有一个 Interface 接口,并且在服务提供者那边有个类 ServiceImpl 实现了这个接口,并且需要创建这个实现类的一个对象服务提供给消费者。在提供者方使用列如:

<bean id="tDubboServiceImpl"class="com.huazai.b2c.aiyou.service.impl.TDubboServiceImpl" />

这句创建了被提供的那个 tDubboServiceImpl,再用 ref="tDubboServiceImpl" 指明你要提供的就是 bean id="tDubboServiceImpl" 的那个对象,在服务端用

 <dubbo:serviceinterface="com.huazai.b2c.aiyou.service.TDubboService"ref="tDubboServiceImpl" />

来接收,使用的时候通过 Interface 这个共同的接口类型来引用,这样就能拿到 service 并且使用了

总的一句话:

这个问题在于没有那个服务提供的实现类的Bean的引用,没有它的对象,在指明 ref 时并不能对应一个确实存在的对象,这个 ref 指定引用是空的,所以才导致 “ Cannot resolve reference to bean 'tDubboServiceImpl' while setting bean property 'ref'; ”。

完整示例内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context"xmlns:p="http://www.springframework.org/schema/p"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsdhttp://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsdhttp://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd"><!-- 配置service扫描包 --><context:component-scan base-package="*" /><!-- 缺省的 tDubboServiceImpl --><bean id="tDubboServiceImpl" class="classpath.TDubboServiceImpl" /><!-- 使用Dubbo发布服务 --><dubbo:application name="aiyou-manager" /><dubbo:registry protocol="zookeeper"address="***.***.***.***:21801" /><dubbo:protocol name="dubbo" port="20880" /><!-- 声明需要暴露的服务端口 --><dubbo:service interface="classpth.TDubboService"ref="tDubboServiceImpl" /></beans>

好了,关于 NoSuchBeanDefinitionException: No bean named 'tDubboServiceImpl' is defined 的解决办法 就写到这儿了,如果还有什么疑问或遇到什么问题欢迎扫码提问,也可以给我留言哦,我会一一详细的解答的。 
歇后语:“ 共同学习,共同进步 ”,也希望大家多多关注CSND的IT社区。


作       者: 华    仔
联系作者: who.seek.me@java98k.vip
来        源: CSDN (Chinese Software Developer Network)
原        文: https://blog.csdn.net/Hello_World_QWP/article/details/90344499
版权声明: 本文为博主原创文章,请在转载时务必注明博文出处!

NoSuchBeanDefinitionException: No bean named 'tDubboServiceImpl' is defined 的解决办法相关推荐

  1. org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'xx' is defined

    概述 出现了org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'xx' is defined ...

  2. Consider defining a bean named 'entityManagerFactory' in your configuration解决办法

    错误信息: *************************** APPLICATION FAILED TO START ***************************Description ...

  3. SpringMVC莫名其妙出现No bean named 'cacheManager' is defined错误

    2019独角兽企业重金招聘Python工程师标准>>> 在使用Interiij idea创建SpringMVC项目时,莫名其妙出现了No bean named 'cacheManag ...

  4. Route [register] not defined. 的解决办法

    Laravel框架运行时ErrorException thrown with message "Route [register] not defined. 的解决办法 目录 Laravel框 ...

  5. partial is not defined的解决办法

    1.partial is not defined的解决办法 .安装express-partials.  方法一:运行cmd用npm install express-partials  方法二:在pac ...

  6. Vue中:error ‘XXXXX‘ is not defined no-undef解决办法

    Vue中:error 'XXXXX' is not defined no-undef解决办法 语法没错居然报错了 解决方法: 拓展 语法没错居然报错了 解决方法: 在使用vue的时候,使用一个全局变量 ...

  7. Vue中error ‘XXXXX‘ is not defined no-undef解决办法

    Vue中:error 'XXXXX' is not defined no-undef解决办法 语法没错居然报错了 解决方法: 拓展 语法没错居然报错了 解决方法: 在使用vue的时候,使用一个全局变量 ...

  8. junit测试NoSuchBeanDefinitionException: No bean named ‘dataSource‘ is define

    junit测试这个问题坑了我两次,印象很深刻,这都是什么bean找不到的问题,其实这个问题很简单,就是spring的配置文件没有全部加载到junit测试环境. 我们要做的就是要检查一下,所有的spri ...

  9. No bean named 'dataSource' is defined

    jar包导入多了,导jar包只需引用一次,如果dao层引用了pojo,然后service只需引用dao就可以引用pojo,然后重新maven install  就好了 如果删除导入多余的jar包不行, ...

最新文章

  1. Survey | 深度学习方法在生物网络中的应用
  2. java.util.ServiceLoader源码分析
  3. muduo之TcpClient
  4. matlab中的reshape函数用法
  5. 关于在软件中添加扫描二维码功能的详细步骤及对应的资源。
  6. 字符串的模式匹配--BF算法KMP算法
  7. linux 之学习路线
  8. SVN 分支与主干的合并
  9. 华为网络设备交换机路由器查看MAC地址表项命令方法
  10. Swift学习笔记 -- 枚举和结构
  11. python程序员前景-一个6年Python程序员的工作感悟,送给还在迷茫的你
  12. 《老爸老妈浪漫史》Barney和Robin终于。。。
  13. 地图编辑器开发(二)
  14. 一个老程序员的教诲(2)
  15. 四川大学计算机专业调剂,四川大学计算机学院(软件学院)2019考研调剂信息...
  16. 如何加粗线条html,PS线条如何加粗,加深?
  17. Springboot 设置post参数大小: 解决报错The multi-part request contained parameter data (excluding uploaded files
  18. 一门编程语言的通用知识点
  19. 飞越680pro+pixhack装机有感
  20. 品AAAI文章的写作结构

热门文章

  1. 如何写长尾关键词的文章
  2. 第一章 命题逻辑 1.7 推理理论
  3. audio音频不能自动播放的解决方法
  4. 搭建ntp时间同步服务器,解决cm时间问题
  5. 初学CSS动画之行走的米兔
  6. 电影《战狼2》的可视化分析
  7. VR-AR应用如何改变我们的城市生活?
  8. matlab小端模式合并,大端方式和小端模式【YC】
  9. VSPD虚拟串口工具实用工具--小白入门篇
  10. 机器翻译质量评测算法-BLEU