title: Connecting dynamically to different databases using spring boot
body: <p><strong><em>How can I connect to multiple databases which are non-identical on the fly (loading the type and connection info of the DB from my DB) using Spring?</em></strong></p>
  
  <pre><code>what I am trying to build?
  I am building a Spring-Boot application that should be able to get data from my customers in the following ways:
  1. Connect to my customer SQL DB (MySQL, MSSQL, PostgreSQL,etc...)
  2. connect to my customer MongoDB,
  3. read data from CSV/JSON files.
  </code></pre>
  
  <p>While the app is running it gets an HTTP request with customer id. to connect to. at this point, the app should load this customer from my DB (that contain exactly what DB he's using and the credentials to connect to it) and should init a connection to this DB to be able to start query it. (<em>DB Schemas are different between 1 customer to another so I also maintain a set of queries in my DB to query the customer</em>)</p>
  
  <p>I'm struggling to implement the blue part of the diagram:</p>
  
  <p><a href="https://i.stack.imgur.com/fHmzR.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fHmzR.jpg" alt="I&#39;m struggling to implement the blue part of the diagram"></a></p>