title: Spring autowiring order and @PostConstruct
body: <p>I have a question about auto-wiring order and <code>@PostConstruct</code> logic in Spring. For example following demo code I have a main Spring Boot class:</p>
  
  <pre><code>@SpringBootApplication
  public class Demo1Application {
  
      @Autowired
      BeanB beanb;
  
      public static void main(String[] args) {
          SpringApplication.run(Demo1Application.class, args);
      }
  }
  </code></pre>
  
  <p>and 2 <code>@Service</code> Definitions:</p>
  
  <pre><code>@Service
  public class BeanB {
  
      @Autowired
      private BeanA beana ;
  
      @PostConstruct
      public void init(){
          System.out.println("beanb is called");
      }
  
      public void printMe(){
          System.out.println("print me is called in Bean B");
      }
  }
  
  @Service
  public class BeanA {
  
      @Autowired
      private BeanB b;
  
      @PostConstruct
      public void init(){
          System.out.println("bean a is called");
          b.printMe();
      }
  }
  </code></pre>
  
  <p>and I have the following output:</p>
  
  <blockquote>
    <p>bean a is called </p>
    
    <p>print me is called in Bean B </p>
    
    <p>beanb is called</p>
  </blockquote>
  
  <p><br>
  My question is how autowiring takes place step by step like a scenario above?<br>
  And how <code>printMe()</code> method of <code>beanb</code> is called without calling its <code>@PostConstruct</code> first?</p>