title: What is the proper way to activate @PostConstruct via CommonAnnotationBeanPostProcessor by Java configuration?
body: <p>I'm using Spring 4 with SpringBoot and Spring-Web with Java configuration. </p>
  
  <p>To have my <a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#beans-postconstruct-and-predestroy-annotations" rel="noreferrer"><code>@PostConstruct</code></a> annotated methods executed by Spring at launch, it is necessary to register <code>CommonAnnotationBeanPostProcessor</code> with the context, otherwise <code>@PostConstruct</code> is ignored. </p>
  
  <p>In a XML-based Spring configuration, the docs say to use (under the beans element)</p>
  
  <pre><code>&lt;context:annotation-config/&gt;
  </code></pre>
  
  <p>I have also seen an example where registration is done on an individual bean basis, like so:</p>
  
  <pre><code>&lt;bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" /&gt;
  </code></pre>
  
  <p>I wish to avoid this if possible. My project does not include any XML file, and none is generated for me in my build folder.</p>
  
  <p>Currently, my solution is to annotate my class with <a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#beans-scanning-autodetection" rel="noreferrer"><code>@ComponentScan</code></a>, which I believe causes Spring to detect and register <code>@Component</code>s and <code>@Bean</code>s. 
  Somehow, this causes <code>CommonAnnotationBeanPostProcessor</code> to be invoked, although I have no idea why, but it solves my problem!</p>
  
  <p>(This class has one <code>@Autowired</code> property, which is null at startup - hence the need to do the initialization via <code>@PostConstruct</code>)</p>
  
  <p>But again, my question, what is the <em>proper</em> way to achieve this using Java configuration? Thank you!</p>