title: Spring Boot - two datasources configured - how to use second datasource?
body: <p>I have configured two schemas from MySQL database in my <code>Spring Boot</code> application and have marked one datasource as Primary.</p>
  
  <p>Now, my question is how can I "use" second datasource? I am using <code>JpaRepository</code> based approach and when I try to save something to a table which resides in second DB schema, my Spring boot application always try to find this table in first DB schema and eventually throws table does not exist error.</p>
  
  <p>P.S. I have marked second DB schema in my <code>Entity</code> class correctly.</p>
  
  <p>Below is my <code>application.properties</code> file (prefix has been changed to omit confidential name):</p>
  
  <pre><code># source 1
  myframework.data.sql.connections.dataSource.url=jdbc:mysql://localhost:3306/schema1?autoReconnect=true&amp;useSSL=false&amp;rewriteBatchedStatements=true
  myframework.data.sql.connections.dataSource.user=root
  myframework.data.sql.connections.dataSource.password=root
  myframework.data.sql.connections.dataSource.driver-class-name=com.mysql.jdbc.Driver
  myframework.data.sql.connections.dataSource.config.preferredTestQuery=select 1 from dual
  
  # source 2
  myframework.data.sql.connections.master.url=jdbc:mysql://localhost:3306/schema2?autoReconnect=true&amp;useSSL=false&amp;rewriteBatchedStatements=true
  myframework.data.sql.connections.master.user=root
  myframework.data.sql.connections.master.password=root
  myframework.data.sql.connections.master.driver-class-name=com.mysql.jdbc.Driver
  </code></pre>