首先创建A,B两个对象,再创建测试类。
@Service
@Lazy
public class A {
@Autowired
public B b;
public B getB() {
return b;
}
public void setB(B b) {
this.b = b;
}
}
@Service
@Lazy
public class B {
@Autowired
public A a;
public A getA() {
return a;
}
public void setA(A a) {
this.a = a;
}
}
@ComponentScan
public class BeanT {
public static void main(String[] args) {
}
@Test
public void testGet(){
AnnotationConfigApplicationContext ann = new AnnotationConfigApplicationContext(BeanT.class);
ann.getBean(A.class);
}
}
首先进入debug模式
再进入getBean