title: Spring Boot - Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured
body: <p>I want to configure two datasources in my SpringBoot (version 2.4) application.</p>
  <p>Below is the application.properties:</p>
  <pre><code>spring.datasource2.url=jdbc:postgresql://localhost:5432/db1
  spring.datasource2.username=//username
  spring.datasource2.password=//pwd
  spring.datasource2.initialization-mode=always
  spring.datasource2.driver-class-name=org.postgresql.Driver
  
  spring.datasource1.url=jdbc:postgresql://localhost:5432/db2
  spring.datasource1.username=//usrename
  spring.datasource1.password=//pwd
  spring.datasource1.initialization-mode=always
  spring.datasource1.driver-class-name=org.postgresql.Driver
  
  spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
  spring.jpa.hibernate.show-sql=true
  spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
  
  spring.jpa.hibernate.ddl-auto=none
  spring.jpa.properties.hibernate.id.new_generator_mappings=false
  logging.level.org.hibernate.SQL=DEBUG
  logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
  
  spring.h2.console.enabled=true
  spring.datasource.continue-on-error=true
  
  spring.servlet.multipart.max-file-size=50MB
  
  spring.servlet.multipart.max-request-size=50MB
  
  
  project.http.enable=false
  project.https.port=9090
  
  spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
  
  server.os=LINUX
  
  dl.writeTOFile=false
  dl.writeTOConsole=true
  </code></pre>
  <p>Below is my pom.xml:</p>
  <pre><code>&lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&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;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;!-- marked the embedded servlet container as provided --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-batch&lt;/artifactId&gt;
          &lt;/dependency&gt;
          
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-validation&lt;/artifactId&gt;
              &lt;version&gt;2.4.0&lt;/version&gt;
          &lt;/dependency&gt;
  </code></pre>
  <p>When I run the application, I get the following error:</p>
  <pre><code>***************************
  APPLICATION FAILED TO START
  ***************************
  
  Description:
  
  Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
  
  Reason: Failed to determine a suitable driver class
  
  
  Action:
  
  Consider the following:
      If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
      If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
  </code></pre>
  <p>When I add one datasource as Spring.datasource and other as Spring.datasource1, application starts up fine but it is looking into the DB configured in Spring.datasource only.</p>
  <p>Following is the DB1 Config class:</p>
  <pre><code>@Configuration
  @EnableTransactionManagement
  @EnableJpaRepositories( entityManagerFactoryRef = &quot;DB1EntityManagerFactory&quot;, transactionManagerRef = &quot;DB1TransactionManager&quot;,    basePackages = {
      &quot;com.datasource1.repository&quot; } )
  @EntityScan(&quot;com.datasource1.entity&quot; )
  public class Db1Config {
      
          @Primary
          @Bean
          @ConfigurationProperties(&quot;spring.datasource&quot;)
          public DataSourceProperties SourceProperties() {
              return new DataSourceProperties();
          }
          
          @Primary
          @Bean( name = &quot;DB1Datasource&quot; )
          @ConfigurationProperties( prefix = &quot;spring.datasource.configuration&quot; )
          public DataSource dataSource()
          {
              return SourceProperties().initializeDataSourceBuilder()
                      .type(HikariDataSource.class).build();
          }
          
          @Primary
          @Bean( name = &quot;DB1EntityManagerFactory&quot; )
          public LocalContainerEntityManagerFactoryBean barEntityManagerFactory( EntityManagerFactoryBuilder builder,
                  @Qualifier( &quot;DB1Datasource&quot; ) DataSource dataSource )
          {
              return builder.dataSource(dataSource).packages(&quot;com.datasource1.entity&quot;)
                      .persistenceUnit(&quot;db1&quot;).build();
          }
          
          @Primary
          @Bean( name = &quot;DB1TransactionManager&quot; )
          public PlatformTransactionManager barTransactionManager(
                  @Qualifier( &quot;DB1EntityManagerFactory&quot; ) EntityManagerFactory barEntityManagerFactory )
          {
              return new JpaTransactionManager(barEntityManagerFactory);
          }
  }
  </code></pre>
  <p>Following is the DB2Config:</p>
  <pre><code>@Configuration
  @EnableTransactionManagement
  @EnableJpaRepositories( entityManagerFactoryRef = &quot;DB2EntityManagerFactory&quot;, transactionManagerRef = &quot;DB2TransactionManager&quot;,    basePackages = {
      &quot;com.DB2.repository&quot; } )
  @EntityScan( &quot;com.DB2.entity&quot; )
  public class Db2Config {
      
          @Bean
          @ConfigurationProperties(&quot;spring.datasource2&quot;)
          public DataSourceProperties DB2SourceProperties() {
              return new DataSourceProperties();
          }
  
          
          @Bean( name = &quot;DB2Datasource&quot; )
          @ConfigurationProperties( prefix = &quot;spring.datasource2.configuration&quot; )
          public DataSource dataSource()
          {
              return DB2SourceProperties().initializeDataSourceBuilder()
                      .type(HikariDataSource.class).build();
          }
          
          @Bean( name = &quot;DB2EntityManagerFactory&quot; )
          public LocalContainerEntityManagerFactoryBean barEntityManagerFactory( EntityManagerFactoryBuilder builder,
                  @Qualifier( &quot;DB2Datasource&quot; ) DataSource dataSource )
          {
              return builder.dataSource(dataSource).packages(&quot;com.DB2.entity&quot;)
                      .persistenceUnit(&quot;db2&quot;).build();
          }
          
          @Bean( name = &quot;DB2TransactionManager&quot; )
          public PlatformTransactionManager barTransactionManager(
                  @Qualifier( &quot;DB2EntityManagerFactory&quot; ) EntityManagerFactory barEntityManagerFactory )
          {
              return new JpaTransactionManager(barEntityManagerFactory);
          }
  }
  </code></pre>
  <p>How do I resolve this issue?</p>