NoUniqueBeanDefinitionException: No qualifying bean of type ‘XXXX‘ available: expected single matchi
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相关推荐
- 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 ...
- 解决org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 异常
在spring中出现: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of ...
- 解决org.springframework.beans.factory.NoUniqueBeanDefinitionException No qualifying bean of type
在spring中出现: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of ...
- org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type错误的解决办法
很多学者在使用Spring工厂的时候会报出这个错误,这个其实很简单,不是唯一Bean的错误,就是你的Bean创建的不是唯一的,系统无法确定是哪一个Bean,犯这种错的大多数都是通过类来获取Bean的 ...
- SpringBoot启动问题:No qualifying bean of type ‘XXX‘ available: ...
**记录:**SpringBoot 启动问题:No qualifying bean of type 'XX' available: expected at least 1 bean which qua ...
- 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 ...
- 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 ...
- 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 ...
- 解决 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type的问题...
具体错误如下: Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying be ...
- No qualifying bean of type xxx‘ available 的一种解决方法
No qualifying bean of type xxx' available 的一种解决方法 参考文章: (1)No qualifying bean of type xxx' available ...
最新文章
- 技术图文:Matlab向量 VS. Python列表
- 使用IntelliJ IDEA 14和Maven创建java web项目
- 专家观点:你必须了解的嵌入式Linux特性
- php 运行外部程序_PHP在linux上执行外部命令的方法
- mysql 优化配置参数(my.cnf)
- SpringCloud Gateway 服务网关,过滤器
- mysql 5.7 内存占用_MySQL 5.7 内存使用计算
- 关于jqGrid动态改变列的解决方案
- WPF 去除头部,实现拖动
- 机外码、区位码、国标码、机内码
- HTTP 报文及作用
- 使用ftl生成word
- android EditText的美化
- DNS 的工作原理——域名系统
- ubuntu QT Creator Fatal IO error 2 (没有那个文件或目录) on X server :0
- RocketMQ源码解析之消息生产者(获取topic路由信息)
- 第三方支付接口申请流程
- ipad和android平板应用,排名前100的iPad应用中只有一半支持Android平板
- CAD图纸无法复制粘贴该怎么办?
- 计算机开机无法选择用户界面,带有win10双系统中win10关机后开机无法进入启动菜单选择及BIOS界面的原因你知道吗?...