在使用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. AWS上的实例无法ping通的解决方案

    首先Ping只是向服务器发送ICMP的数据包,如果在服务器的防火墙没有允许ICMP协议的数据包的话,那么即使服务器正常运行,那也是ping不同的. 对于亚马逊云服务器,首先我们要确保实例绑定的安全组允 ...

  2. VMWare之——宿主机与虚拟机互相ping通,宿主机ping通另一台机器的虚拟机

    版权声明:本文为博主原创文章,未经博主允许不得转载. 转载请注明出处:http://blog.csdn.NET/l1028386804/article/details/52267554 今天给大家带来 ...

  3. jndi连接数据库配置过程总结

    一.我们先找到tomcat安装目录中conf目录下的context.xml更改里面的内容: <?xml version='1.0' encoding='utf-8'?> <Conte ...

  4. [转帖]华为Hi 1620 等ARM 服务器版本CPU信息.

    华为ARM服务器恐依赖党政输血续命 一旦制裁立马休克 http://www.sohu.com/a/240833070_99934330 几年前,ARM服务器被业界炒的火热,AMD.高通.Marvell ...

  5. Java 反射 调用 demo

    基础类.供demo反射练习 package fanshe; public class Person { public String name; private String age; private ...

  6. onMeasure实例分析

    本文转自:http://blog.csdn.net/u012604322/article/details/17097105           上面这个两个视图是Android API中没有给出来的但 ...

  7. 多线程同步与并发访问共享资源工具—Lock、Monitor、Mutex、Semaphore

    “线程同步”的含义   当一个进程启动了多个线程时,如果需要控制这些线程的推进顺序(比如A线程必须等待B和C线程执行完毕之后才能继续执行),则称这些线程需要进行“线程同步(thread synchro ...

  8. 【loj6145】「2017 山东三轮集训 Day7」Easy 动态点分治+线段树

    题目描述 给你一棵 $n$ 个点的树,边有边权.$m$ 次询问,每次给出 $l$ .$r$ .$x$ ,求 $\text{Min}_{i=l}^r\text{dis}(i,x)$ . $n,m\le ...

  9. 015 反射中的 Class.forName() 与 ClassLoader.loadClass() 的区别

    作者:nnngu GitHub:https://github.com/nnngu 博客园:http://www.cnblogs.com/nnngu 简书:https://www.jianshu.com ...

  10. ava8并发教程:Threads和Executors

    原文地址  原文作者:Benjamin Winterberg 译者:张坤 欢迎阅读我的Java8并发教程的第一部分.这份指南将会以简单易懂的代码示例来教给你如何在Java8中进行并发编程.这是一系列教 ...