title: Autowired property is null - Spring Boot Configuration
body: <p>I am stuck with null values in an autowired property. I am hoping I could get some help.</p>
  
  <p>We are using for the project spring-boot version 0.5.0.M6.</p>
  
  <p>The four configuration files with beans are in one package and are sorted by "area":</p>
  
  <ol>
  <li>Data source configuration</li>
  <li>Global method security configuration (as we use Spring-ACL)</li>
  <li>MVC configuration</li>
  <li>Spring Security configuration</li>
  </ol>
  
  <p>The main method that bootstraps everything is in the following file:</p>
  
  <pre><code>@EnableAspectJAutoProxy
  @EnableSpringConfigured
  @EnableAutoConfiguration(exclude = {
      DataSourceTransactionManagerAutoConfiguration.class,
      HibernateJpaAutoConfiguration.class,
      JpaRepositoriesAutoConfiguration.class,
      SecurityAutoConfiguration.class,
      ThymeleafAutoConfiguration.class,
      ErrorMvcAutoConfiguration.class,
      MessageSourceAutoConfiguration.class,
      WebSocketAutoConfiguration.class
  })
  @Configuration
  @ComponentScan
  public class IntegrationsImcApplication {
  
      public static void main(String[] args) throws Exception {
          ApplicationContext ctx = SpringApplication.run(
                  IntegrationsImcApplication.c lass, args);
      }
  }
  </code></pre>
  
  <p>The first file that holds the data source configuration beans is as follows (I have omitted some method body parts to make it more readable):</p>
  
  <pre><code>@EnableTransactionManagement(mode = AdviceMode.ASPECTJ)
  @Configuration
  public class RootDataSourceConfig 
          extends TomcatDataSourceConfiguration 
          implements TransactionManagementConfigurer {
  
      @Override
      public DataSource dataSource() {
          return jpaDataSource();
      }
  
      public PlatformTransactionManager annotationDrivenTransactionManager() {
          return jpaTransactionManager();
      }
  
      @Bean
      public HibernateExceptionTranslator hibernateExceptionTranslator() {
          return new HibernateExceptionTranslator();
      }
  
      @Bean(name="jpaDataSource")
      public DataSource jpaDataSource() {......}
  
      @Bean(name = {"transactionManager","txMgr"})
      public JpaTransactionManager jpaTransactionManager() {......}
  
      @Bean(name = "entityManagerFactory")
      public EntityManagerFactory jpaEmf() {......}
  }
  </code></pre>
  
  <p>And here is the next configuration file, that depends on the data source from above. It has about 20 beans related to ACL configuration, but it fails on the firsts bean that uses data source:</p>
  
  <pre><code>@EnableGlobalMethodSecurity(prePostEnabled = true)
  @Configuration
  public class RootGlobalMethodSecurityConfig 
          extends GlobalMethodSecurityConfiguration 
          implements Ordered {
  
      @Autowired
      public DataSource dataSource;
  
      @Override
      public int getOrder() {
          return IntegrationsImcApplication.ROOT_METHOD_SECURITY_CO NFIG_ORDER;
      }
  
      @Bean
      public MutableAclService aclService() 
              throws CacheException, IOException {
  
          MutableJdbcAclService aclService = new MutableJdbcAclService(
                  dataSource, aclLookupStrategy(), aclCache());
          aclService.setClassIdentityQuery("SELECT @@IDENTITY");
          aclService.setSidIdentityQuery("SELECT @@IDENTITY");
          return aclService;
      }
  
      ...................................
  }
  </code></pre>
  
  <p>Basically invoking <code>aclService()</code> throws an error as <code>dataSource</code> is null. We have tried ordering the configuration files by implementing the <code>Ordered</code> interface. We also tried using <code>@AutoConfigureAfter(RootDataSourceConfig.class)</code> but this did not help either. Instead of doing <code>@Autowired</code> on the <code>DataSource</code> we also tried injecting the <code>RootDataSourceConfig</code> class itself, but it was still null. We tried using <code>@DependsOn</code> and <code>@Ordered</code> on those beans but again no success. It seems like nothing can be injected into this configuration.</p>
  
  <p>The console output at the startup is listing the beans in the order we want them, with data source being the first. We are pretty much blocked by this.</p>
  
  <p>Is there anything weird or unique we are doing here that is not working? If this is as designed, then how could we inject data source differently?</p>
  
  <p>Repo: <a href="https://github.com/doles/spring-boot-autowired-sample" rel="nofollow noreferrer">github</a></p>