title: Autowire a bean within Spring's Java configuration
body: <p>Is it possible to use Spring's <code>@Autowired</code> annotation within a Spring configuration written in Java?</p>
  
  <p>For example:</p>
  
  <pre><code>@Configuration
  public class SpringConfiguration{
  
     @Autowired 
     DataSource datasource;
  
     @Bean
     public DataSource dataSource(){
         return new dataSource();
     }
  
     // ...
  
  }
  </code></pre>
  
  <p>Obviously a DataSource interface cannot be directly instantiated but I directly instantiated it here for simplification.  Currently, when I try the above, the datasource object remains null and is not autowired by Spring.</p>
  
  <p>I got <code>@Autowired</code> to work successfully with a Hibernate <code>SessionFactory</code> object by returning a <code>FactoryBean&lt;SessionFactory&gt;</code>.</p>
  
  <p>So my question specifically: is there a way to do that with respect to a <code>DataSource</code>?  Or more generally, what is the method to autowire a bean within a Spring Java Configuration?</p>
  
  <p>I should note I am using Spring version 3.2.</p>