異常信息:org.springframework.beans.factory.UnsatisfiedDependencyException:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.byd.mes.bussiness.service.siteoperation.activity.ExecuteActivityService] is defined: expected single matching bean but found 2: [executeActivityService, executeActivityForTesterService]
解決方案:
博文鏈接地址:http://haowei0315.javaeye.com/blog/444731
@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://blog.csdn.net/hjjzhangkui/article/details/6052329
