title: Spring Boot 2 Multiple Datasource - work only the one with @Primay annotation
body: <p>I have a problem, I'm trying to use two Oracle databases in spring boot using DataSource, The DataSource wiht the @Primay annotation works fine but the oher one only gives me:</p>
  <pre><code>SQL Error: 942, SQLState: 42000
  ORA-00942: table or view does not exist
  </code></pre>
  <p>I don't have idea what I should do now. Any help will be welcomed. Thanks!</p>
  <p>application.properties</p>
  <pre><code>spring.datasource.url=jdbc\:oracle\:thin\:[connection] #Not showing for security
  spring.datasource.password=[password]
  spring.datasource.configuration.maximum-pool-size=30
  
  spring.sgc-datasource.url=jdbc\:oracle\:[connection] #Not showing for security
  spring.sgc-datasource.username=[user]
  spring.sgc-datasource.password=[password]
  spring.sgc-datasource.max-total=30
  
  spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
  spring.jpa.database=default
  spring.jpa.hibernate.ddl-auto=none
  </code></pre>
  <p>pom.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.5.4&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
      &lt;groupId&gt;com.indra.vmo.edenorte&lt;/groupId&gt;
      &lt;artifactId&gt;InMpData&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;name&gt;InMpData&lt;/name&gt;
      &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
      &lt;properties&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
      &lt;dependencies&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-validation&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-devtools&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
              &lt;optional&gt;true&lt;/optional&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.oracle.database.jdbc&lt;/groupId&gt;
              &lt;artifactId&gt;ojdbc8&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-tomcat&lt;/artifactId&gt;
              &lt;scope&gt;provided&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;com.google.code.gson&lt;/groupId&gt;
              &lt;artifactId&gt;gson&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-configuration-processor&lt;/artifactId&gt;
              &lt;optional&gt;true&lt;/optional&gt;
          &lt;/dependency&gt;
          &lt;!-- https://mvnrepository.com/artifact/commons-dbcp/commons-dbcp --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;commons-dbcp&lt;/groupId&gt;
              &lt;artifactId&gt;commons-dbcp&lt;/artifactId&gt;
              &lt;version&gt;1.2.2&lt;/version&gt;
          &lt;/dependency&gt;
          
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  <p>DatabaseConfiguration.java</p>
  <pre><code>package com.indra.vmo.edenorte.config;
  
  import org.apache.commons.dbcp.BasicDataSource;
  import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
  import org.springframework.boot.context.properties.ConfigurationProperties;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.Primary;
  
  import com.zaxxer.hikari.HikariDataSource;
  
  @Configuration(proxyBeanMethods = false)
  public class DatabaseConfiguration {
      
      @Bean
      @Primary
      @ConfigurationProperties(&quot;spring.datasource&quot;)
      public DataSourceProperties inMpDataSourceProperties() {
          return new DataSourceProperties();
      }
      
      @Bean
      @Primary
      @ConfigurationProperties(&quot;spring.datasource.configuration&quot;)
      public HikariDataSource inMpDataSource(DataSourceProperties inMpDataSourceProperties) {
          return inMpDataSourceProperties.initializeDataSourceBuilder().type(HikariDataSource.class).build();
      }
      
      @Bean
      @ConfigurationProperties(&quot;spring.sgc-datasource&quot;)
      public DataSourceProperties sgcDataSourceProperties() {
          return new DataSourceProperties();
      }
      
      @Bean
      @ConfigurationProperties(&quot;spring.sgc-datasource.configuration&quot;)
      public HikariDataSource sgcDataSource(DataSourceProperties sgcDataSourceProperties) {
          return sgcDataSourceProperties.initializeDataSourceBuilder().type(HikariDataSource.class).build();
      }
      
  }
  </code></pre>
  <p>Repository from 1st DB</p>
  <pre><code>package com.indra.vmo.edenorte.repository.inmp;
  
  import org.springframework.data.jpa.repository.JpaRepository;
  import org.springframework.stereotype.Repository;
  
  import com.indra.vmo.edenorte.entity.inmp.MpLocalidadesCoordenadas;
  
  @Repository
  public interface IMpLocalidadesCoordenadasRepository extends JpaRepository&lt;MpLocalidadesCoordenadas, String&gt; {
  
  }
  </code></pre>
  <p>Repository from 2nd DB</p>
  <pre><code>package com.indra.vmo.edenorte.repository.sgc;
  
  import org.springframework.data.jpa.repository.JpaRepository;
  import org.springframework.data.jpa.repository.Query;
  import org.springframework.stereotype.Repository;
  
  import com.indra.vmo.edenorte.entity.sgc.Clientes;
  
  @Repository
  public interface IClientesRepository extends JpaRepository&lt;Clientes, Integer&gt; {
  
      @Query(&quot;select c from Clientes c where c.docId=?1&quot;)
      public Clientes findBydocId(String docId);
      
      @Query(&quot;select c from Clientes c where c.docId=?1 and c.tipDoc=?2&quot;)
      public Clientes findBydocIdU(String docId, String tipDoc);
  }
  </code></pre>