![](/img/trans.png)
[英]Spring configuration in Java - Create and use 2 beans of same class NOT using Autowired
[英]Spring (autowired) component use multiple in the same class
我最近已经开始使用Spring。 而且我没有找到解决问题的方法。
我有一个组成部分:
@Component
@Scope(value = "prototype", proxyMode = ScopedProxyMode.TARGET_CLASS)
@Log4j2
public class CompX { ....
我想在(组件)类中使用两次:
...
@Autowired
private CompX current;
@Autowired
private CompX old;
...
我怎样才能做到这一点? 总是有以下异常。
“ org.springframework.beans.factory.NoUniqueBeanDefinitionException:没有符合条件的bean类型...”
这是因为歧义性和spring混淆了要考虑的那个,所以请通过以下限定告诉spring要使用哪个:
@Autowired
@Qualifier("current")
private CompX current;
@Autowired
@Qualifier("old")
private CompX old;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.