title: How to @Inject A Bean into a Java Class?
body: <p>I am working on learning Spring and Java.  I created a Spring 3 app and tried to make a connection pool as a bean:</p>
  
  <pre><code> @Bean
   public ComboPooledDataSource comboPooledDataSource() {
  
      ComboPooledDataSource pool = new ComboPooledDataSource();
      // configure here
   }
  </code></pre>
  
  <p>Then in another class:</p>
  
  <pre><code>public class DatabaseQuery {
  
  @Inject private ComboPooledDataSource comboPooledDataSource;
  
  private Connection getConnection() {
      try {
          return comboPooledDataSource.getConnection();
      } catch (SQLException e) {
          e.printStackTrace();
      }
      return null;
  }
  </code></pre>
  
  <p>From some debugging statements I can see the connection pool is successfully created, but when I use the comboPooledDataSource, I get a NullPointerException.  How to I get the bean and use it?  Am I doing this wrong?</p>