Spring autowiring order and @PostConstruct

Below should be possible sequence

  1. beanb starts to get autowired
  2. During class initialization of Beanb, beana starts to get autowired
  3. Once beana gets created the @PostConstruct i.e. init() of beana gets called
  4. Inside init(), System.out.println("bean a is called"); gets called
  5. Then b.printMe(); gets called causing System.out.println("print me is called in Bean B"); to execute
  6. Having the beana completed the @PostConstruct i.e. init() of beanb gets called
  7. 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.

Leave a Comment