title: Basic Spring JDBC application, JdbcTemplate bean not found
body: <p>A bean definition of type <code>org.springframework.jdbc.core.JdbcTemplate</code> was not found, therefore <code>@Autowired private JdbcTemplate jdbcTemplate;</code> doesn't actually have a value inside it.<br>
  My <strong>Application.java</strong> looks as following:</p>
  
  <pre><code>public static void main(String[] args) {
      SpringApplication.run(Application.class, args);
  }
  
  @Value("${spring.name}")
  private String name;
  
  @Autowired
  private JdbcTemplate jdbcTemplate;
  
  private static final Logger log = LoggerFactory.getLogger(Application.class);
  
  //    @Bean
  //    public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
  //        return args -&gt; {
  //            System.out.printf("The application is running %s!", name);
  //        };
  //    }
  
  public void run(String... strings) throws Exception {
  
      log.info("Creating tables");
  
      jdbcTemplate.execute("DROP TABLE customers IF EXISTS");
      jdbcTemplate.execute("CREATE TABLE customers(" +
              "id SERIAL, first_name VARCHAR(255), last_name VARCHAR(255))");
  
      // Split up the array of whole names into an array of first/last names
      List&lt;Object[]&gt; splitUpNames = Arrays.asList("John Woo", "Jeff Dean", "Josh Bloch", "Josh Long").stream()
              .map(name -&gt; name.split(" "))
              .collect(Collectors.toList());
  
      // Use a Java 8 stream to print out each tuple of the list
      splitUpNames.forEach(name -&gt; log.info(String.format("Inserting customer record for %s %s", name[0], name[1])));
  
      // Uses JdbcTemplate's batchUpdate operation to bulk load data
      jdbcTemplate.batchUpdate("INSERT INTO customers(first_name, last_name) VALUES (?,?)", splitUpNames);
  
      log.info("Querying for customer records where first_name = 'Josh':");
      jdbcTemplate.query(
              "SELECT id, first_name, last_name FROM customers WHERE first_name = ?", new Object[] { "Josh" },
              (rs, rowNum) -&gt; new CustomerModel(rs.getLong("id"), rs.getString("first_name"), rs.getString("last_name"))
      ).forEach(customer -&gt; log.info(customer.toString()));
  }
  </code></pre>
  
  <p>I understand Dependency Injection and IoC which should technically instantiate a JdbcTemplate instance by itself, but if I do it manually it I have the following code which gives the error that <code>JdbcTemplate</code> bean requires <code>dataSource</code> property (which I'm giving as below):</p>
  
  <pre><code>@Value("${spring.datasource.url}")
  private String dbUrl;
  
  @Value("${spring.datasource.username}")
  private String dbUsername;
  
  @Value("${spring.datasource.password}")
  private String dbPassword;
  
  private DataSource dataSource = new DriverManagerDataSource(dbUrl, dbUsername, dbPassword);
  
  private JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
  </code></pre>