在使用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的更多相关文章

  1. 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 ...

  2. 深入Spring Boot:怎样排查expected single matching bean but found 2的异常

    写在前面 这个demo来说明怎么排查一个常见的spring expected single matching bean but found 2的异常. https://github.com/hengy ...

  3. spring依赖注入单元测试:expected single matching bean but found 2

    异常信息:org.springframework.beans.factory.UnsatisfiedDependencyException: Caused by: org.springframewor ...

  4. spring " expected single matching bean but found 2" 问题一例。

    初入java,使用spring时遇到一个问题,左边是一个接口和实现.右边是service和实现. @Service@Transactional(rollbackFor = Exception.clas ...

  5. 多个@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 ' ...

  6. expected single matching bean but found 2

    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'acc ...

  7. 多数据源报错 expected single matching bean but found 2: xxx,xxx

    问题: expected single matching bean but found 2: xxx,xxx 原因:在 Spring 容器中配置了两个类型Bean,Spring 容器将无法确定到底要用 ...

  8. 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< ...

  9. expected single matching bean but found 2: menusServiceImpl,IMenusService

    问题如下: 接口也作为匹配的bean? 有点迷惑了....... 经过在网上找资料,发现和@MapperScan这个注解有关系,具体源码不止.但是这个注解会扫描路径下的所有类. 去掉这个注解就可以正常 ...

随机推荐

  1. javascript 组件化(转载)

    这边只是很简陋的实现了类的继承机制.如果对类的实现有兴趣可以参考我另一篇文章javascript oo实现 我们看下使用方法: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...

  2. js 算法

    var str=‘abscdf’; function solution(str){ var arr=new Array(); if(str.length%2==0){ for(i=0;i<str ...

  3. js数组遍历 千万不要使用for...in...

    昨天做个下拉框 扩充了一下数组的方法 Array.prototype.remove = function (val) { var index = this.indexOf(val); if (inde ...

  4. Inside Qt Series (全集,共十六篇,不同版本的Qt有不同的实现)

    Inside Qt 系列 QObject这个 class 是 QT 对象模型的核心,绝大部分的 QT 类都是从这个类继承而来.这个模型的中心特征就是一个叫做信号和槽(signaland slot)的机 ...

  5. gitlab 本地建库配置 config

    先下git(?)https://download.tortoisegit.org/tgit/2.6.0.0/ 小乌龟下载 http://gitlab.didu86.com:9090/wxcode/fa ...

  6. STM32标准外设库、 HAL库、LL库

    工作以来一直使用ST的STM32系列芯片,ST为开发者提供了非常方便的开发库.到目前为止,有标准外设库(STD库).HAL库.LL库 三种.前两者都是常用的库,后面的LL库是ST最近才添加,目前支持的 ...

  7. 当给属性添加final 时候 则无法进行第二次值的修改

  8. 基于c的简易计算器一

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include <malloc.h&g ...

  9. Eclipse中设置作者、日期等的方式

    1.点击Windows->Preferences->Java->Code Style->Code Templates: 2.点击展开右侧的Comments选项卡,里面的选项对应 ...

  10. BZOJ3252 攻略(贪心+dfs序+线段树)

    考虑贪心,每次选价值最大的链.选完之后对于链上点dfs序暴力修改子树.因为每个点最多被选一次,复杂度非常正确. #include<iostream> #include<cstdio& ...