在开发自己淘宝客网站配置spring 遇到问题:expected single matching bean but found 2
来源:互联网 发布:mysql 大于小于转义 编辑:程序博客网 时间:2024/05/20 11:20
@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://www.blogjava.net/caizh2009/articles/290019.html
- 在开发自己淘宝客网站配置spring 遇到问题:expected single matching bean but found 2
- 遇到问题---MongoDB---配置多数据源报错expected single matching bean but found 2
- spring注解错误-expected single matching bean but found 2
- expected single matching bean but found 2
- expected single matching bean but found 2
- expected single matching bean but found 2
- expected single matching bean but found 2
- Injection expected single matching bean but found
- expected single matching bean but found 2 注解继承冲突
- 多数据源报错 expected single matching bean but found 2
- spring依赖注入单元测试:expected single matching bean but found 2
- spring依赖注入单元测试:expected single matching bean but found 2
- spring依赖注入单元测试:expected single matching bean but found 2
- 深入Spring Boot:怎样排查expected single matching bean but found 2的异常
- 开发:异常收集之 expected single matching bean but found 2
- Spring的JUnit错误:NoSuchBeanDefinitionException: No unique bean of type,expected single matching bean but found 2 [dataSource1,data
- spring boot+mybatis 多数据源报错 expected single matching bean but found
- No qualifying bean of type is defined: expected single matching bean but found 2
- re模块 compile函数
- Java学习笔记-Scanner和BufferedReader的区别和用法
- Python 字符串操作
- extern
- Struts.xml解析
- 在开发自己淘宝客网站配置spring 遇到问题:expected single matching bean but found 2
- eclipse建立Dynamic Web Project 时没有web.xml
- UVA 437 The Tower of Babylon
- FirefoxOS横竖屏切换应用开发一般方法总结
- 9*9乘法表
- MR_Android View Client 问题总结及代码片段
- 一步一步教你在Ubuntu12.04搭建gstreamer开发环境
- 博客开通了
- 微软:经调查88%的用户表示喜欢WP手机