spring依赖注入单元测试:expected single matching bean but found 2
异常信息:org.springframework.beans.factory.UnsatisfiedDependencyException:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.byd.mes.bussiness.service.siteoperation.activity.ExecuteActivityService] is defined: expected single matching bean but found 2: [executeActivityService, executeActivityForTesterService]
解决方案:
博文链接地址:http://haowei0315.javaeye.com/blog/444731
@Qualifier
@Autowired是根据类型进行自动装配的。在上面的例子中,如果当Spring上下文中存在不止一个UserDao类型的bean时,就会抛出BeanCreationException异常;如果Spring上下文中不存在UserDao类型的bean,也会抛出BeanCreationException异常。我们可以使用@Qualifier配合@Autowired来解决这些问题。
1. 可能存在多个UserDao实例
- @Autowired
- public void setUserDao(@Qualifier("userDao") UserDao userDao) {
- this.userDao = userDao;
- }
这样,Spring会找到id为userDao的bean进行装配。
2. 可能不存在UserDao实例
- @Autowired(required = false)
- public void setUserDao(UserDao userDao) {
- this.userDao = userDao;
- }
http://blog.csdn.net/hjjzhangkui/article/details/6052329
spring依赖注入单元测试:expected single matching bean but found 2的更多相关文章
- 深入Spring Boot:怎样排查expected single matching bean but found 2的异常
写在前面 这个demo来说明怎么排查一个常见的spring expected single matching bean but found 2的异常. https://github.com/hengy ...
- Spring 3.2 @Autowired异常:expected single matching bean but found 2
在使用Sping做单元测试时候,对RequestMappingHandlerAdapter(从处理器包装过来的适配器)进行自动装配, 发现报:expected single matching bean ...
- spring " expected single matching bean but found 2" 问题一例。
初入java,使用spring时遇到一个问题,左边是一个接口和实现.右边是service和实现. @Service@Transactional(rollbackFor = Exception.clas ...
- 多个@bean无法通过@resource注入对应的bean(org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected single matching bean but found )
一.异常 org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type ' ...
- Spring Boot 自定义配置文件异常"expected single matching bean but found 2"
运行环境:Spring Boot 2.5.0, IDEA 2020.3.2 异常详细信息: Injection of resource dependencies failed; nested exce ...
- 多数据源报错 expected single matching bean but found 2: xxx,xxx
问题: expected single matching bean but found 2: xxx,xxx 原因:在 Spring 容器中配置了两个类型Bean,Spring 容器将无法确定到底要用 ...
- expected single matching bean but found 2
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'acc ...
- MyBatis Plus:No qualifying bean of type 'com.baomidou.mybatisplus.mapper.BaseMapper<?>' available: expected single matching bean but found 4
场景: 应用MyBatis Plus 和通用Mapper 继承自ServiceImpl实现对Service里的方法进行包装再处理. public interface IServiceBase2< ...
- expected single matching bean but found 2: menusServiceImpl,IMenusService
问题如下: 接口也作为匹配的bean? 有点迷惑了....... 经过在网上找资料,发现和@MapperScan这个注解有关系,具体源码不止.但是这个注解会扫描路径下的所有类. 去掉这个注解就可以正常 ...
随机推荐
- 我给女朋友讲编程html系列(4) -- html常用简单标签
今天似乎有点感冒,浑身无力,在操场上躺了半个小时,好了许多.好了,废话不说了,还是写今天的教程吧. 1,html中的换行标签是 br,写法是: <br /> 2,html中有一些特殊的字符 ...
- RobotFramework-关键字
地址:https://github.com/NitorCreations/RobotFramework-EclipseIDE/tree/master/plugin/robot-indices Coll ...
- Python 删除列表中的重复数据
list0=['b','c', 'd','b','c','a','a'] 方法1:使用set() list1=sorted(set(list0),key=list0.index) # sorted o ...
- linux 操作
正在运行的内核和系统信息 # uname -a # 获取内核版本(和BSD版本) # lsb_release -a # 显示任何 LSB 发行版版本信息 # cat /etc/SuSE-release ...
- 【CentOS】安装chrome
参考资料:http://www.cnblogs.com/xia520pi/p/3545715.html 问题描述: 出现如下错误: 升级glibc任然无效,最后在博客园:http://www.cnbl ...
- 【UOJ Easy Round #2】
然而UER我也照样跪…… 第一题 忘了取模sad || 操作符将整个区间分成了一些段,每个手机只会执行其中某一段,执行次数为这一段中&&的个数?+1? ans=ans*num[i]+1 ...
- objc swift 混编
原链接:http://blog.csdn.net/xuanwenchao/article/details/30226823 在xocde6出来我们大部分代码都是用objective-c写的(部分C/C ...
- lua与 object-C 通信
IOS中如何调用LUA,以及LUA如何调用IOS中的功能 下面将讲解一下如何在iOS里调用Lua函数,以及Lua函数如何调用iOS本地函数. 转载请注明出处.原文出处 http://www.cnblo ...
- skinned mesh 蜘蛛样
被skinned mesh 折磨了 好久,开始感觉skinindices不对,因为pix显示里面全是0 后来跟来跟去发现是这样的,那些uchar的整数被pix用float的格式显示出来 (显示为0.0 ...
- samba 常见问题
今天帮一个朋友搭建samba服务器,发现总是无法正常访问,最后google+摸索搞定了,下面把遇到的问题和解决方法共享一下. 这里用的linux是centos版本6. 一开始遇到的问题是‘找不到网络路 ...