title: (Spring-boot & Spring data jpa) How to change the datasource on the fly?
body: <p>For my new project, I built a basic rest api to return data at the client request. However, the client must select the databse of his choice, as a parameter of the HTTP GET request. </p>
  
  <p>Now my question is that I don't know how to do that with Sprint-boot. I know that we can provide many different datasources, but how can we change the desired datasource after inspecting the request ?</p>
  
  <p>Here is my data sources config, which works well : </p>
  
  <pre><code>@Configuration
  public class DataSourceConfig {
  
      @Bean
      @Primary
      @ConfigurationProperties(prefix="datasource.dev21")
      public DataSource dev21DataSource() throws SQLException {
          return DataSourceBuilder.create().build();
      }
  
      @Bean
      @ConfigurationProperties(prefix="datasource.dev22")
      public DataSource dev22DataSource() throws SQLException {
          return DataSourceBuilder.create().build();
      }
  } 
  </code></pre>
  
  <p>If I want to switch between dev21 and dev22 dynamically, what should I do ? 
  I have read articles about the class <strong>AbstractRoutingDataSource</strong>, but I don't know how to use it.</p>