Attempting to create a class that will be used by JavaConfig as a source of bean definitions.
(尝试创建一个将由JavaConfig用作bean定义源的类。)
@Configuration
public class MyClass {
@Bean
@ConditionalOnProperty(name = "property")
public A fuction1() {
doSomething1(); // may return an exception
}
@Bean
@ConditionalOnMissingBean(name = "fuction1")
public A fuction2() {
doSomething2();
}
@Bean
public B fuction3(A a) {
doSomething3(a);
}
}
The third bean definition has the error "could not autowire. There is more than one bean of A type."
(第三个bean定义具有错误"could not autowire. There is more than one bean of A type."
)
How do I tell Spring to try to autowire the first A and if it is missing then to try the second A, ie following the conditional process described. (我如何告诉Spring尝试自动连接第一个A,如果缺少它,然后尝试第二个A,即遵循所述的条件过程。)
Hopefully that makes sense. (希望这是有道理的。)
Thanks! (谢谢!)
ask by Chris Johnston translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…