当前位置: 首页 > 知识库问答 >
问题:

NouniQueBeanDefinitionException:…需要一个匹配bean,但找到2:

严升
2023-03-14

我有这个超级班:

@Component
public class DAOBase {
}
@Component
public class VoceDAO extends DAOBase{       
}
@Service
public class TransactionService {
    @Autowired
    private DAOBase dAOBase;
}
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [com.jeansedizioni.dao.DAOBase] is defined: expected single matching bean but found 2: DAOBase,voceDAO
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:865)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:770)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)
    ... 37 more
@Component("DAOBaseBeanName")
public class DAOBase {
}

谢谢你。

共有1个答案

陶高扬
2023-03-14

尝试添加@qualifier注释,如下所示:

 @Autowired
 @Qualifier("dAOBase")
 private DAOBase dAOBase;

指定要在类中注入哪个bean(daobasevocedao)。

 类似资料: