Below should be possible sequence
beanb
starts to get autowired- During class initialization of
Beanb
, beana starts to get autowired - Once beana gets created the
@PostConstruct
i.e.init()
of beana gets called - Inside
init()
,System.out.println("bean a is called");
gets called - Then
b.printMe();
gets called causingSystem.out.println("print me is called in Bean B");
to execute - Having the
beana
completed the@PostConstruct
i.e.init()
ofbeanb
gets called - Then
System.out.println("beanb is called");
gets called
Ideally the same can be better observed by a debugger in eclipse.
The Spring reference manual explains how circular dependencies are resolved. The beans are instantiated first, then injected into each other.