Spring 3.2 @Autowired异常:expected single matching bean but found 2
在使用Sping做单元测试时候,对RequestMappingHandlerAdapter(从处理器包装过来的适配器)进行自动装配,
发现报:expected single matching bean but found 2异常,意思是需要匹配单个Bean,但是却找到两个;
我在spring-servlet.xml中的确配置了一个,不知道第二个从哪里来的,一般这种情况下可以使用@Qualifier配合@Autowired来解决这些问题;
另外我预计是因为bean没有给id属性导致的,然后我在spring-servlet.xml配置中给bean添加了一个id和需要注入的变量名称一致,这个时候正常运行了。
后续还碰到一个问题,关于Spring3.2 Controller单元测试参数的问题,会再下篇文章中给出整个配置和测试代码。
Spring 3.2 @Autowired异常:expected single matching bean but found 2的更多相关文章
- 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 ...
- 深入Spring Boot:怎样排查expected single matching bean but found 2的异常
写在前面 这个demo来说明怎么排查一个常见的spring expected single matching bean but found 2的异常. https://github.com/hengy ...
- spring依赖注入单元测试:expected single matching bean but found 2
异常信息:org.springframework.beans.factory.UnsatisfiedDependencyException: Caused by: org.springframewor ...
- 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 ' ...
- expected single matching bean but found 2
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'acc ...
- 多数据源报错 expected single matching bean but found 2: xxx,xxx
问题: expected single matching bean but found 2: xxx,xxx 原因:在 Spring 容器中配置了两个类型Bean,Spring 容器将无法确定到底要用 ...
- 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这个注解有关系,具体源码不止.但是这个注解会扫描路径下的所有类. 去掉这个注解就可以正常 ...
随机推荐
- Print Nodes in Top View of Binary Tree
Top view of a binary tree is the set of nodes visible when the tree is viewed from the top. Given a ...
- ACM数论之旅9---中国剩余定理(CRT)(壮哉我大中华╰(*°▽°*)╯)
中国剩余定理,又名孙子定理o(*≧▽≦)ツ 能求解什么问题呢? 问题: 一堆物品 3个3个分剩2个 5个5个分剩3个 7个7个分剩2个 问这个物品有多少个 解这题,我们需要构造一个答案 我们需要构造这 ...
- ACM数论之旅5---数论四大定理(你怕不怕(☆゚∀゚)老实告诉我)
(本篇无证明,想要证明的去找度娘)o(*≧▽≦)ツ ----------数论四大定理--------- 数论四大定理: 1.威尔逊定理 2.欧拉定理 3.孙子定理(中国剩余定理) 4.费马小定理 (提 ...
- Class.getResourceAsStream 和 ClassLoder.getResourceAsStream 的区别
问题描述 最近学习MyBaits时用到了 InputStream Resources.getResourceAsStream(String resource)来读取MyBatis配置文件,为了方便使用 ...
- javascript中boolean类型和其他类型的转换
在javascript中,if语句括号中的表达式返回值可以是任何类型,即:if(a)中的a可以是boolean.number.string.object.function.undefined中的任何类 ...
- java的4种引用 强软弱虚
&lt;img src="https://pic4.zhimg.com/d643d9ab5c933ac475cfa23063bed137_b.png" data-r ...
- laravel运行慢是怎么回事?
因为默认的 hello 页面引用了 google 的字体,至于为什么 google 这么慢就不用我详细说明了吧.
- Oracle 修改dmp的表空间
1.百度下载 UltraEdit 并安装 2.打开程序,文件-->打开-->找到dmp 文件太大会提示,选择第一个默认,确定 3.按CTRL+H 转成十六进制编辑 4.例如:dmp里面 ...
- 百度地图经纬度批量查找功能XGeocoding使用手册
<XGeocoding使用手册> 1.下载XGeocoding V2 http://www.gpsspg.com/xgeocoding/download/ 2.解压XGeocoding_v ...
- MT【157】至少一个小于1
若函数$f(x)=x^2+ax+b$有两个不等实数根$x_1,x_2$,且$1<x_1<x_2<3$,那么$f(1),f(3)中$ ( )A.只有一个小于1 B.至少 ...