title: How to autowire jdbcTemplate in springboot?
body: <p>Trying to access Oracle database using JdbcTemplate with SpringBoot 2.1.4.RELEASE, but I am getting a null pointer exception</p>
  
  <p>Tried below as per the SpringBoot documentation I still got null pointer exception.</p>
  
  <pre><code>@Component
  public class DataAccessObject {
  
      private final JdbcTemplate jdbcTemplate;
  
      @Autowired
      public DataAccessObject(JdbcTemplate jdbcTemplate) {
          this.jdbcTemplate = jdbcTemplate;
      }
  
      // ...
  
  }
  </code></pre>
  
  <p>Null Pointer Exception is thrown in getCircleCount()</p>
  
  <pre><code>@Component
  public class DataAccessObject {
  
      @Autowired
      private JdbcTemplate jdbcTemplate;
  
      public void getCircleCount() {
          int count = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM CIRCLE", Integer.class);
          System.out.println(count);
      }
  }
  </code></pre>
  
  <p>whereas I am getting the circle count here</p>
  
  <pre><code>@SpringBootApplication
  @ComponentScan("org.vinodh.camunda")
  public class DatabaseDemoApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(DatabaseDemoApplication.class, args);
          DataAccessObject dao = new DataAccessObject();
          dao.getCircleCount();
      }
  
      @Bean
      public CommandLineRunner commandLineRunner(ApplicationContext context) {
          JdbcTemplate jdbcTemplate = (JdbcTemplate) context.getBean("jdbcTemplate");
          int count = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM CIRCLE", Integer.class);
          System.out.println(count);
          return null;
      }
  
  }
  </code></pre>
  
  <p>Actually shouldn't I be getting the count at both the places ?</p>