假设我有这样的接口:
interface Country {}
class USA implements Country {}
class UK implements Country ()
Run Code Online (Sandbox Code Playgroud)
这个配置xml片段:
<bean class="USA"/>
<bean id="country" class="UK"/>
<bean id="main" class="Main"/>
Run Code Online (Sandbox Code Playgroud)
如何控制下面自动连接的依赖项?我想要英国人.
class Main {
private Country country;
@Autowired
public void setCountry(Country country) {
this.country = country;
}
}
Run Code Online (Sandbox Code Playgroud)
我使用的是Spring 3.0.3.RELEASE.
我有一个应用程序有2个同名的bean,但它们在不同的包中.我的Spring应用程序失败,因为它无法决定采用哪个bean.这有什么解决方案吗?Bean目前不实现特定的接口.
请参阅下面一个已编辑的异常示例:
Caused by:
org.springframework.context.annotation.ConflictingBeanDefinitionException:
Annotation-specified bean name 'dataTransferHandler' for bean class
[aaaaa.ws.handler.DataTransferHandler] conflicts with existing,
non-compatible bean definition of same name and class
[bbbbb.ws.handler.DataTransferHandler]
Run Code Online (Sandbox Code Playgroud)