title: Unable to create Postgres datasource programatically using Spring
body: <p>I am trying to create a DataSource as is suggested in some Spring examples online this way:</p>
  
  <pre><code>    @Configuration
  public class RepositoryConfiguration {
  
      @Primary
      @Bean
      @ConfigurationProperties(prefix = "spring.datasource")
      public DataSource dataSource() {
          return DataSourceBuilder.create().build();
      }
  
  }
  </code></pre>
  
  <p>I have an application.yml file that looks like this:</p>
  
  <pre><code>spring:
    datasource:
      driver-class-name: org.postgresql.Driver
      url: jdbc:postgresql://localhost:54320/mydb
      username: postgres
      password: somepassword
  </code></pre>
  
  <p>When I run the debugger and evaluate <code>DataSourceBuilder.create().build();</code> the values don't seem to be set. Any idea what could be missing?</p>
  
  <p><a href="https://i.stack.imgur.com/Wa749.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Wa749.png" alt="enter image description here"></a></p>
  
  <p>I am using version 2.2.4 of Spring boot</p>
  
  <p>This is my <code>build.gradle</code> file</p>
  
  <pre><code>buildscript {
      repositories {
          mavenLocal()
          mavenCentral()
      }
      dependencies {
          classpath "org.postgresql:postgresql:42.2.11"
      }
  }
  
  plugins {
      id 'org.springframework.boot' version '2.2.4.RELEASE'
      id 'io.spring.dependency-management' version '1.0.9.RELEASE'
      id 'java'
      id 'org.flywaydb.flyway' version '6.3.0'
      id 'nu.studer.jooq' version '4.1'
  }
  
  group 'com.solution.asclepius'
  version '1.0-SNAPSHOT'
  
  sourceCompatibility = 1.8
  
  repositories {
      mavenCentral()
  }
  
  dependencies {
  
      annotationProcessor 'org.projectlombok:lombok:1.18.8'
  
      implementation 'org.jooq:jooq'
      implementation 'org.jooq:jooq-codegen'
      jooqRuntime 'org.postgresql:postgresql:42.2.11'
      implementation 'org.projectlombok:lombok:1.18.8'
      implementation 'org.springframework.boot:spring-boot-starter-web'
      implementation 'org.springframework.boot:spring-boot-starter-actuator'
      implementation 'org.springframework.boot:spring-boot-starter-jooq'
      implementation 'io.vavr:vavr:0.10.2'
  
      testCompile group: 'junit', name: 'junit', version: '4.12'
      testCompile group: 'org.mockito', name: 'mockito-core', version: '2.1.0'
      testCompile group: 'org.assertj', name: 'assertj-core', version: '3.15.0'
  
  }
  
  jooq {
      sample(sourceSets.main) {
          jdbc {
              driver = 'org.postgresql.Driver'
              url = 'jdbc:postgresql://localhost:54320/asclepiusdb'
              user = 'postgres'
              password = 'somepassword'
          }
          generator {
              database() {
                  name = 'org.jooq.meta.postgres.PostgresDatabase'
                  inputSchema = 'public'
                  includes = '.*'
              }
              target {
                  packageName = 'com.solution.asclepius'
                  directory = 'build/generated/java'
              }
          }
      }
  }
  
  tasks.generateSampleJooqSchemaSource.with {
      def out = new ByteArrayOutputStream()
      javaExecSpec = { JavaExecSpec s -&gt;
          s.standardOutput = out
          s.errorOutput = out
          s.ignoreExitValue = true
          s.jvmArgs '-Xmx512M'
      }
      execResultHandler = { ExecResult r -&gt;
          if (r.exitValue != 0) {
              throw new RuntimeException('jOOQ source code generation failed:\n\n' + out.toString())
          }
      }
  }
  
  flyway {
      url = 'jdbc:postgresql://localhost:54320/asclepiusdb'
      user = 'postgres'
      password = 'somepassword'
      schemas = ['public']
      locations = ["filesystem:$project.projectDir/src/main/resources/db/migration"]
  }
  </code></pre>
  
  <p>At the moment the app is failing to boot:</p>
  
  <pre><code>***************************
  APPLICATION FAILED TO START
  ***************************
  
  Description:
  
  Failed to bind properties under 'spring.datasource' to javax.sql.DataSource:
  
      Property: spring.datasource.driver-class-name
      Value: org.postgresql.Driver
      Origin: class path resource [application.yml]:4:24
      Reason: Failed to load driver class org.postgresql.Driver in either of HikariConfig class loader or Thread context classloader
  
  Action:
  
  Update your application's configuration
  </code></pre>