我有这样的spring Bean类:
public class A{
@Autowired
private B b;
@Autowired
private C c;
@Autowired
private D d;
public A(){
}
public A(B b){
this.b = b;
}
}
我有一些初始化B类的spring xml bean配置文件,但是我也有一些初始化 A 类的spring java配置类:
@Configuration
public AConfigurator(){
@Bean
public A create(){
B b = new B();
A a = new A(b); //I set specific B instance
return a; //my already set b property will be overried(with the bean B that has already been created in the spring context by another xml configuration) by the spring when autowiring the properties
}
}
我的问题是,当 create 方法返回 A 时,即使已设置属性,弹簧也会自动连接属性。它将覆盖已经设置的 b 属性。我只想自动装配在构造函数中未设置的属性。春季有可能吗?