title: Spring Boot externalised configuration for DataSource not working
body: <p>I have an application - using Spring 4.3.6 and Spring Boot 1.4.4 - which will be exported as a JAR. I want to connect to a remote Oracle database but I am having trouble externalising the configuration without breaking the application.</p>
  
  <p>This is my current workaround:</p>
  
  <pre><code>import org.apache.tomcat.jdbc.pool.DataSource;
  
  @Bean
  public DataSource dataSource() {
    DataSource dataSource = new DataSource();
  
    dataSource.setUrl("jdbc:oracle:thin:@ip-address:port:orcl");
    dataSource.setUsername("user");
    dataSource.setPassword("password");
    dataSource.setDriverClassName("oracle.jdbc.OracleDriver");
  
    return dataSource;
  }
  </code></pre>
  
  <p>With the above, my application is able to connect to the database and execute queries successfully. However, when I try to externalise the configuration as follows:</p>
  
  <pre><code>@Bean
  @ConfigurationProperties(prefix="app.datasource")
  public DataSource dataSource() {
    return new DataSource();
  }
  
  // application.properties
  app.datasource.url=jdbc:oracle:thin:@ip-address:port:orcl
  app.datasource.username=user
  app.datasource.password=password
  app.datasource.driver-class-name=oracle.jdbc.OracleDriver
  </code></pre>
  
  <p>I will get the following error when trying to execute <code>jdbcTemplate.update(query)</code> in my Spring Boot Controller (note that without externalising the above works):</p>
  
  <pre><code>org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: The url cannot be null
  </code></pre>
  
  <p>I have tried to remove <code>@ConfigurationProperties</code> and change <code>app.datasource</code> to <code>spring.datasource</code>.  I have also tried to use <code>DataSourceBuilder.create().build()</code> which returns <code>javax.sql.DataSource</code> but the same error is thrown in both cases.</p>
  
  <p>I'm doing something wrong. What's the correct way to successfully externalise the configuration?</p>