Spring循环依赖-spring源码详解(四)
上篇文章说了,bean工厂后置处理器如何加载配置类
public static void loadBeanDefinitions() {
RootBeanDefinition rootBeanDefinitionA = new RootBeanDefinition(InstanceA.class);
RootBeanDefinition rootBeanDefinitionB = new RootBeanDefinition(InstanceB.class);
beanDefinitionMap.put("instanceA", rootBeanDefinitionA);
beanDefinitionMap.put("instanceB", rootBeanDefinitionB);
}
@Component
public class InstanceA {
@Autowired
private InstanceB instanceB;
public InstanceB getInstanceB() {
return instanceB;
}
public void setInstanceB(InstanceB instanceB) {
this.instanceB = instanceB;
}
public InstanceA(InstanceB instanceB) {
this.instanceB = instanceB;
}
public InstanceA() {
System.out.println("实例化A");
}
}
相关文章