Unable to create database connection with multiple dataSources
<p>I am getting the following error:</p>

<pre><code>***************************
APPLICATION FAILED TO START
***************************

Description:

Field dataSource in com.domain.ws.actuator.RandomActuator required a bean of type 'javax.sql.DataSource' that could not be found.
    - Bean method 'dataSource' not loaded because @ConditionalOnProperty (spring.datasource.type) did not find property 'spring.datasource.type'
    - Bean method 'dataSource' not loaded because @ConditionalOnProperty (spring.datasource.jndi-name) did not find property 'jndi-name'
    - Bean method 'dataSource' not loaded because @ConditionalOnBean (types: org.springframework.boot.jta.XADataSourceWrapper; SearchStrategy: all) did not find any beans

Action:

Consider revisiting the conditions above or defining a bean of type 'javax.sql.DataSource' in your configuration.
</code></pre>

<p>I uniquely identified the dataSources names with <code>@ConfigurationProperties(prefix="spring.fooDataSource")</code> then put <code>spring.fooDataSource.url: ${dbURI}</code> in the <code>yml</code> file. Example:</p>

<p>Config class</p>

<pre><code>@Configuration
@PropertySource({"classpath:application.yml"})
public class RequestDataSource {

    /*******************************
     *      foo Datasource     *
     * *****************************/
    @Bean
    @Primary
    @ConfigurationProperties(prefix="spring.fooDataSource")
    public DataSource primaryDataSource() {
        return DataSourceBuilder.create().build();
    }

    /*******************************
     * foo Transaction manager *
     * *****************************/
    @Bean(name="tm1")
    @Primary
    @Autowired
    DataSourceTransactionManager tm1(@Qualifier("primaryDataSource") DataSource datasource) {
        DataSourceTransactionManager txm  = new DataSourceTransactionManager(datasource);
        return txm;
    }

}
</code></pre>

<p>second dataSource class</p>

<pre><code>@Configuration
@PropertySource({"classpath:application.yml"})
public class KeyviewDataSource {

    /*******************************
     *     Second Datasource      *
     * *****************************/
    @Bean
    @ConfigurationProperties(prefix="spring.secondDataSource")
    public DataSource secondaryDataSource() {
        return DataSourceBuilder.create().build();
    }

    /*******************************
     * Second Transaction manager *
     * *****************************/
    @Bean(name="tm2")
    @Autowired
    DataSourceTransactionManager tm2(@Qualifier("secondaryDataSource") DataSource datasource) {
        DataSourceTransactionManager txm  = new DataSourceTransactionManager(datasource);
        return txm;
    }

}
</code></pre>

<p>Application.yml</p>

<pre><code>spring:

  fooDataSource.url: ${dbURI}
  fooDataSource.username: ${dbUsername}
  fooDataSource.password: ${dbPassword}
  fooDataSource.driverClassName: oracle.jdbc.OracleDriver

  secondDataSource.url: ${dbURIkeyview}
  secondDataSource.username: ${dbUSERNAMEkeyview}
  secondDataSource.password: ${dbPasswordKeyview}
  secondDataSource.driverClassName: oracle.jdbc.OracleDriver
</code></pre>

<p>I am using gradle and in this module I did add the dependency it needs:</p>

<pre><code>compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: springBootVersion
    // https://mvnrepository.com/artifact/org.hibernate/hibernate-java8
    compile group: 'org.hibernate', name: 'hibernate-java8', version: '5.0.0.CR1'
</code></pre>

<p>----------------------------------Update 1----------------------------------</p>

<h1>Note</h1>

<p>In my applications.yml file Intellij is highlighting my dataSources in yellow and when hover over them it reads <code>"Cannot resolve configuration property"</code> </p>

<p>-------------------------Update 2------------------------------</p>

<p>Due to so many changes I created a new question that is related to this one<a href="https://stackoverflow.com/questions/40746554/could-not-find-version-optional-for-arguments">HERE</a></p>

<p>-------------------------------Update 3------------------------------</p>

<p>I got rid of the issue with update one by creating a <code>spring-configuration-metadata.json</code> file
 and doing the following:</p>

<pre><code>{
    "properties": [
        {
            "name": "spring.fooDataSource.username",
            "type": "java.lang.String",
            "description": "Description for spring.requestDataSource.username."
        },
        {
            "name": "spring.fooDataSource.url",
            "type": "java.lang.String",
            "description": "Description for spring.requestDataSource.url."
        },
        {
            "name": "spring.fooDataSource.driverClassName",
            "type": "java.lang.String",
            "description": "Description for spring.requestDataSource.driverClassName."
        },
</code></pre>

<p>and placing it in the resources folder.</p>