title: Spring loads component before the needed bean
body: <p>I have an annotation based configuration class in my Spring project:</p>
  
  <pre><code>@Configuration
  @EnableWebMvcSecurity
  public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
  
      @Bean(name = "LDAP_TEMPLATE_BEAN")
      public LdapTemplate configLdapTemplate() {
          System.out.println("BEAN LDAP LOADED");
          LdapContextSource lcs = new LdapContextSource();
          lcs.setUrl("ldap://127.0.0.1:33389/");
  //      lcs.setUserDn(BASE_DN);
          lcs.setDirObjectFactory(DefaultDirObjectFactory.class);
  //      lcs.setAnonymousReadOnly(true);
          lcs.afterPropertiesSet();
          return new LdapTemplate(lcs);
      }
  </code></pre>
  
  <p>And a component class which needs the defined bean:</p>
  
  <pre><code>@Component
  public class UserRepo {
  
      @Autowired
      private LdapTemplate ldapTemplate; 
  
      public UserRepo() {
          System.out.println("UserRepo created");
  </code></pre>
  
  <p>When I start the project as Spring Boot App, the text of the UserRepo Constructor is shown before the text of the bean on the console output. And indeed, the variable ldapTemplate is null and causes of course exceptions.</p>
  
  <p>How can I let the bean instantiation happen before the component instantiation, so the autowiring of ldapTemplate works?</p>