Spring可配置bean注入

时间:2013-01-02 11:20:59

标签: spring dependency-injection

除了工厂模式之外,有没有办法注入bean依赖项可配置? 我有3个类实现相同的接口并有3个bean定义。我想在其他类中更改那些bean吗?对于例子,是否可以读取bean名称表单conf文件并将其用作varible?

1 个答案:

答案 0 :(得分:3)

是的,您可以使用@Qualifier注释。由于您有3个实现相同接口的类,因此请使用不同名称命名这些类并使用@Qualifier注释。

Spring documentation说:autowiring by type may lead to multiple candidates, it is often necessary to have more control over the selection process. One way to accomplish this is with Spring's @Qualifier annotation.