Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring4:@组件多态性_Spring_Polymorphism_Components - Fatal编程技术网

Spring4:@组件多态性

Spring4:@组件多态性,spring,polymorphism,components,Spring,Polymorphism,Components,春季4.0 @组件和多态性: 我有以下结构 Interface IF { } @Component(value="a") public class AAA implements IF { } @Component(value="b") public class BBB implements IF { } @Component public class Factory { @Autowired @Qualifier("a") private IF

春季4.0 @组件和多态性:

我有以下结构

Interface IF {
}

@Component(value="a")
    public class AAA implements IF {
} 

@Component(value="b")
    public class BBB implements IF {
} 


@Component public class Factory {
    @Autowired
    @Qualifier("a")
    private IF if1;

    @Autowired
    @Qualifier("b")
    private IF if2;
}
与SpringXML不同,它对我不起作用。我想如果我只有一个属性,它会很好地工作。我当然可以

@Autowired
private AAA a;

@Autowired
private BBB b;

。。。但我不想那样做

你的建议应该有用。。。你得到了什么线索?哦,是的,有用。为了改变,我发布了一个答案,而不是一个问题: