spring在进行注入的时候如果发现有两个bean,这时候他是不知道注入哪个bean的,就会报如下的错误:

Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'XXXX' available: expected single matching bean but found 2:

这时候可以在bean的xml文件里给bean配置优先级:

<bean id="hotGenericSearchPartyHandler" class="com.exigen.hot.billing.ui.HotGenericSearchPartyHandler" scope="prototype" primary="true">
</bean>

里面主要就是 primary这个,如果想让这个bean优先被设置的话,就可以加上这个配置

出现这种情况的case:

在运行时创建bean,而不是在spring启动的时候创建的:

ApplicationContext context;
Handler handler = new Handler();
context.getAutowireCapableBeanFactory().autowireBean(handler);

比如在一个类里面有一个接口的引用,但是实现这个接口的类有多个,而且都放到了spring容器中,那在注入的时候,他不知道注入哪一个,所以可以通过设置bean的优先级来决定在有多个bean的时候选择注入哪个

NoUniqueBeanDefinitionException: No qualifying bean of type ‘XXXX‘ available: expected single matchi相关推荐

  1. Spring项目启动报错No qualifying bean of type [xxx] available: expected single matching bean but found 2

    启动报错: No qualifying bean of type [class1] available: expected single matching bean but found 2,class ...

  2. 解决org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 异常

    在spring中出现: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of ...

  3. 解决org.springframework.beans.factory.NoUniqueBeanDefinitionException No qualifying bean of type

    在spring中出现: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of ...

  4. org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type错误的解决办法

    很多学者在使用Spring工厂的时候会报出这个错误,这个其实很简单,不是唯一Bean的错误,就是你的Bean创建的不是唯一的,系统无法确定是哪一个Bean,犯这种错的大多数都是通过类来获取Bean的 ...

  5. SpringBoot启动问题:No qualifying bean of type ‘XXX‘ available: ...

    **记录:**SpringBoot 启动问题:No qualifying bean of type 'XX' available: expected at least 1 bean which qua ...

  6. SpringBootTest报错:No qualifying bean of type...expected at least 1 bean which qualifies as autowire

    已知:报错信息为 Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying b ...

  7. No qualifying bean of type ‘com.xxx.xx.service.xxService‘ available: expected at leas

    No qualifying bean of type 'com.xxxx.xx.service.xxService' available: expected at least 1 bean which ...

  8. No qualifying bean of type 'com.xxx.xx.service.xxService' available: expected at leas

    No qualifying bean of type 'com.xxxx.xx.service.xxService' available: expected at least 1 bean which ...

  9. 解决 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type的问题...

    具体错误如下: Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying be ...

  10. No qualifying bean of type xxx‘ available 的一种解决方法

    No qualifying bean of type xxx' available 的一种解决方法 参考文章: (1)No qualifying bean of type xxx' available ...

最新文章

  1. 技术图文:Matlab向量 VS. Python列表
  2. 使用IntelliJ IDEA 14和Maven创建java web项目
  3. 专家观点:你必须了解的嵌入式Linux特性
  4. php 运行外部程序_PHP在linux上执行外部命令的方法
  5. mysql 优化配置参数(my.cnf)
  6. SpringCloud Gateway 服务网关,过滤器
  7. mysql 5.7 内存占用_MySQL 5.7 内存使用计算
  8. 关于jqGrid动态改变列的解决方案
  9. WPF 去除头部,实现拖动
  10. 机外码、区位码、国标码、机内码
  11. HTTP 报文及作用
  12. 使用ftl生成word
  13. android EditText的美化
  14. DNS 的工作原理——域名系统
  15. ubuntu QT Creator Fatal IO error 2 (没有那个文件或目录) on X server :0
  16. RocketMQ源码解析之消息生产者(获取topic路由信息)
  17. 第三方支付接口申请流程
  18. ipad和android平板应用,排名前100的iPad应用中只有一半支持Android平板
  19. CAD图纸无法复制粘贴该怎么办?
  20. 计算机开机无法选择用户界面,带有win10双系统中win10关机后开机无法进入启动菜单选择及BIOS界面的原因你知道吗?...

热门文章

  1. html5中event获取data和class
  2. JS 使用RSA加密解密
  3. 【android】uiselectoer 自动化测试
  4. 关于不使用web服务实现文本框自动完成扩展
  5. JavaScript—计算图片加载的张数。
  6. [洛谷5463]小鱼比可爱
  7. Java小题,通过JNI调用本地C++共享库中的对应方法实现杨辉三角的绘制
  8. bzoj4033 [HAOI2015]树上染色(树形)
  9. vue.js实现联动效果
  10. 23种设计模式及其应用场景