title: JdbcTemplate object is null in my springboot application - using postgres
body: <p>Here are my spring.datasource properties in application.properties- </p>
  
  <pre><code>        spring.datasource.url=jdbc:postgresql://&lt;hostname goes here&gt;
          spring.datasource.username=&lt;username goes here&gt;
          spring.datasource.password=password
          spring.datasource.driverClassName=org.postgresql.Driver
  </code></pre>
  
  <p>My main class is as follows: </p>
  
  <pre><code>        @PropertySources(value = {@PropertySource("classpath:application.properties")})
          @PropertySource(value = "classpath:sql.properties")
          @SpringBootApplication
          public class MyApp implements CommandLineRunner{
  
              public static void main(String[] args) {
  
                  SpringApplication.run(MyApp.class, args);
              }
  
              @Override
              public void run(String... strings) throws Exception {
                  Execute execute = new Execute();
                  execute.executeCleanUp();
  
              }
          }
  </code></pre>
  
  <p>The Execute class is as follows: </p>
  
  <pre><code>    import com.here.oat.repository.CleanUpEntries;
      import com.here.oat.repository.CleanUpEntriesImpl;
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.jdbc.core.JdbcTemplate;
  
      import java.io.IOException;
  
      /***
       *
       */
  
      public class Execute {
  
          @Autowired
          private CleanUpEntries cleanUpEntries;
  
  
          public void executeCleanUp() throws IOException {
              cleanUpEntries = new CleanUpEntriesImpl();
              cleanUpEntries.delete();
          }
      }
  </code></pre>
  
  <p>Here is the implementation class - CleanupEntriesImpl:</p>
  
  <pre><code>import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.jdbc.core.JdbcTemplate;
  import org.springframework.stereotype.Component;
  
  @Component
  public class CleanUpEntriesImpl implements CleanUpEntries{
  
      @Autowired
      private JdbcTemplate jdbcTemplate;
  
      @Value(value = "${delete.query}")
      private String deleteQuery;
  
      @Override
      public int delete() {
          int id= jdbcTemplate.queryForObject(deleteQuery, Integer.class);
         return id;
      }
  
  }
  </code></pre>
  
  <p>pom.xml has the following dependencies:</p>
  
  <pre><code> &lt;!--jdbc driver--&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-jdbc&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
              &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
              &lt;version&gt;9.4-1201-jdbc41&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
  </code></pre>
  
  <p>Not sure why jdbcTemplate object is null when the delete() method is called. Any ideas?</p>