1

除了工厂模式之外,有没有办法注入 bean 依赖项使其可配置?我有 3 个类实现相同的接口并有 3 个 bean 定义。我想改变在其他班级使用的豆子?例如,是否可以从 conf 文件中读取 bean 名称并将其用作变量?

4

1 回答 1

3

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

Spring文档说: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.

于 2013-01-02T11:33:20.773 回答