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,class1,classImp1
这个问题的根源在于,class1和classImp1都被加入Bean容器管理,但是@AutoWired进行自动注入,没有指定具体class1的ID,那么spring通过反射机制使用byName自动注入策略,将配置文件的value注入,而不是Id值,这就导致找到两个相同的value值,无法选择注入哪一个,导致报错。
通过查找资料,发现可以在@Autowired下面再加上@Qualifier(“类名”)注释,来指定注入具体的注入类。
但是又报出如下错误
No qualifying bean of type [class1] available: expected at least 1 bean which qualifies as autowire candidate
刚开始感觉莫名其妙,后来发现在applicationContext.xml中对于classImpl1的bean已经新增了classImpl1,并且id设置的并不是classImpl1的类名。
所以设置@Qualifier(“bean中classImpl1的id值”)
最终代码
在applicationContext.xml文件中
< bean id="class123Dao" class="xxx.xxx.ClassDaoImpl">
在classServiceImpl(调用ClassDaoImpl类的Service中)
@Autowired
@Qualifier("class123Dao")
ClassDao classDao; //ClassDao是ClassDaoImpl的接口
问题解决。
Spring项目启动报错No qualifying bean of type [xxx] available: expected single matching bean but found 2相关推荐
- SpringBoot项目启动报错:Field userMapper in com.demo.controller.MemberController required a bean of type ‘c
问题描述: SpringBoot项目启动报错,报错内容:'com.xxx.mapper.XxxxMapper' that could not be found ******************** ...
- mybatis项目启动报错 The content of element type resultMap must match (constructor?,id*,result*,associat...
启动项目报错 2018-02-26 17:09:51,535 ERROR [org.springframework.web.context.ContextLoader] - Context initi ...
- spring boot 启动报错:No qualifying bean of type org.springframework.security.oauth2.provider.token.Toke
spring boot启动报错: Exception encountered during context initialization - cancelling refresh attempt: o ...
- 项目启动报错:No qualifying bean of type ‘xxx‘ available:
项目启动报错: Description: A component required a bean of type 'cn.hsa.its.abutment.bo.BusinessAcceptBo' t ...
- 【图文详解】SpringBoot项目启动报错:The bean ‘xxxServiceImpl‘ could not be injected as a ‘xxxServiceImpl‘ ...
问题描述: 项目启动报错:The bean 'xxxServiceImpl' could not be injected as a 'cn.xxxx.service.xxxServiceImpl' b ...
- Linux下Tomcat项目启动报错
Linux下Tomcat项目启动报错 org.springframework.beans.factory.CannotLoadBeanClassException: Error loading cla ...
- 项目启动报错Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error
错误:项目启动报错: Error starting ApplicationContext. To display the conditions report re-run your applicati ...
- Spring boot 启动报错 'elasticsearchTemplate' that could not be found.
Spring boot 启动报错 (a)异常信息 Error starting ApplicationContext. To display the conditions report re-run ...
- springboot项目启动报错-案例情景介绍
文章目录 摘要 情况1:Nacos报错 情况2:IllegalStateException: Incompatible fallbackFactory instance 情况3:idea编译java文 ...
最新文章
- PHP中使用redis执行lua脚本示例
- Python tips(
- 密码学基础知识(十)查缺补漏(缺)
- Spotify模式并非“敏捷涅磐”
- 充电原理_电动汽车充电桩如何设置?充电桩原理介绍
- 隐藏界面没有必要应用场景
- python123查找指定字符输入m_大数据应用人才培养系列教材 Python语言 刘 鹏 张 燕 总主编 李肖俊 主编 刘 河 钟 涛 副主编....
- 神经网络-损失函数-等高线理解
- 13 Process Lifecycle: Process Creation and Termination
- TYPES、DATA、TYPE、LIKE、CONSTANTS、STATICS、TABLES
- QStandardItemModel——数据模型
- DNN Navisuite菜单模块原始XML文件的格式
- 头条2020届实习生笔试题
- 猿创征文|C++软件开发值得推荐的十大高效软件分析工具
- [RK3399][Android7.1][Camera]IMX307 mclk 37.125M补丁
- php 车牌号 正则,php正则验证车牌格式的函数
- JPA 中@Enumerated
- Unity ASE点光源不显示的问题
- ads1115多片并联
- 工程图字体宋体仿宋_设计干货来了!最热门的宋体字要如何设计搭配?
热门文章
- 赴北京美国大使馆L1签证面签记
- 朱晔的互联网架构实践心得S2E1:业务代码究竟难不难写? | 掘金年度征文
- 坚果nuts 加速 官网_5G坚果旗舰手机R2发布售价4499元起 搭载全新Smartisan OS 8.0操作系统...
- Python处理PDF神器:PyMuPDF的安装与使用
- Codeforces Round #486 (Div. 3)
- 【图像分割】基于贝叶斯算法阙值图像分割matlab代码
- Tesseract+OpenCV实现中英文字识别
- Qpython SL4A服务调用GPS定位获取获取位置信息
- 便利贴--14{GIF录制工具}
- 持续爆点:一对一直播和短视频