当找到多个匹配的bean时,Spring如何按名称自动装配? [英] How does Spring autowire by name when more than one matching bean is found?
本文介绍了当找到多个匹配的bean时,Spring如何按名称自动装配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有这样的接口:
interface Country {}
class USA implements Country {}
class UK implements Country ()
这是配置xml的代码段:
And this snippet of configuration xml:
<bean class="USA"/>
<bean id="country" class="UK"/>
<bean id="main" class="Main"/>
如何控制下面自动关联的依赖项?我想要英国.
How can I control which dependency is autowired below? I'd like the UK one.
class Main {
private Country country;
@Autowired
public void setCountry(Country country) {
this.country = country;
}
}
我正在使用Spring 3.0.3.RELEASE.
I am using Spring 3.0.3.RELEASE.
推荐答案
查看全文