title: Order of loading during Spring Java Config
body: <p>I have a Java Config class that looks similar to:</p>
  
  <pre><code>@Configuration
  public class MyConfig {
  
      @Autowired(required = true)
      private MyRegistry registry;
  
      public CustomAttributeConfig() {
          . . .
      }
  
      @Bean
      public IBeanApiType someBeanApi() {
         return new SomeBeanApi();
      }
  
      @PostConstruct
      public void postConstructionCodeHere() {
          registry.register(someBeanApi());
      }
      . . . 
  </code></pre>
  
  <p>Is the order of execution of the <code>@Autowired</code>, <code>@Bean</code>, and <code>@PostConstruct</code> guaranteed in any way?
  What if the <code>@Bean</code> used the <code>@Autowired</code> registry value?</p>
  
  <p>The order of execution I am seeing in my real code is: </p>
  
  <ol>
  <li>the autowired field</li>
  <li>the @PostConstruct annotated method</li>
  <li>the @Bean annotated method</li>
  </ol>
  
  <p>My goal is to have 2 and 3 to execute in reverse order.  How do I know the order of mixtures of these annotations in a Java Config file and what options are available to control that order?</p>
  
  <p><strong>EDITTED!</strong>
  Thought about this some more and while I am interested in the order, that may not really be critical.  I modified the code above slightly to reflect the fact that I want to call the @Bean constructor from the @PostConstruct code.  </p>
  
  <p>This seems to work fine for the very limited tests I have done.  Does anyone know if all the necessary Spring initialization is guaranteed to be finished when a @PostConstruct is called such that calling an @Bean annotated method will always work?  I did step into the calls and see the interceptors being invoked, but I don't know that the proxy I will get back will always be the "right" one, with all the advisors, advice, etc properly attached.</p>