title: Spring3 - @Autowired
body: <p>This is my applicationContext.xml</p>
  
  <pre><code>&lt;bean id="JdbcUserDao" class="controller.User.JdbcUserDao"&gt;
      &lt;property name="dataSource" ref="dataSource"/&gt;
  &lt;/bean&gt;
  
  
  &lt;bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource"
        p:driverClassName="org.apache.derby.jdbc.ClientDriver"
        p:url="jdbc:derby://localhost:1527/TodoDb"
        p:username="root"
        p:password="root" /&gt;
  </code></pre>
  
  <p>This is my implDao class :</p>
  
  <pre><code>@Repository
  public class JdbcUserDao implements IUserDao {
  
      private JdbcTemplate jt;
      @Autowired
      private DataSource dataSource;
  
      public DataSource getDataSource() {
          return dataSource;
      }
  
      public void setDataSource(DataSource dataSource) {
          this.dataSource = dataSource;
              jt = new JdbcTemplate(this.dataSource); 
      }
  
      public JdbcTemplate getJt() {
          return jt;
      }
  
      public void setJt(JdbcTemplate jt) {
          this.jt = jt;
      }
  
  
      @Override
      public List&lt;User&gt; getUsers(final String username, final String password) {
          List&lt;User&gt; users = this.jt.query("SELECT username, password FROM USERS",
              new RowMapper&lt;User&gt;() {
  
                  @Override
                  public User mapRow(ResultSet rs, int i) throws SQLException {
                      User user = new User();
                      user.setUsername(rs.getString("username"));
                      user.setPassword(rs.getString("password"));
                      return user;
                  }
              });
          return users;
      }
  }
  </code></pre>
  
  <p>Problems:</p>
  
  <ul>
  <li>this.dataSource available when it sets the dataSource through @Autowired like the configs in xml</li>
  <li>when I use dataSource in getUsers, it become null ?</li>
  </ul>
  
  <p>Questions:</p>
  
  <ol>
  <li>How can I get this works ?</li>
  </ol>
  
  <p>I'm new to spring3 so I really need your help.</p>