title: Transaction Management for multiple datasources created manually
body: <p>I am working on an application wherein I have to connect to different database depending upon an customer id that is passed from the client side. The schema for all the databases is same. It is a kind of multi-tenant application. Since I don't know how many customers will be there, I cannot use xml configuration to statically create the datasources, hence I have to create datasources manually.</p>
  
  <p>We are using Spring JdbcTemplate for connecting to the databases and the connection parameter comes from another database which holds the configuration for the application. I am able to connect to the databases properly, but the method calls are not happening in a transaction.
  Following is the code snippet which does the database connectivity for only one database and  I was going to extend it for multiple databases:</p>
  
  <pre><code>BasicDataSource datasource = new BasicDataSource();
  // set database connection params
  ....
  // create jdbcTemplate, 
  jdbcTemplate = new JdbcTemplate(datasource);
  // create transaction managers
  PlatformTransactionManager txManager = new DataSourceTransactionManager(datasource);
  </code></pre>
  
  <p>My idea is to create the transaction manager manually and somehow bind it in the spring container so that all the methods/classes with @Transactional annotation can use this transaction manager.
  I am not able to figure how do I bind the txManager, so that all the methods/classes with @Transactional will use this transaction manager. I am not sure whether this is the right way and should I be creating a transaction manager for every datasource, since, I don't want the transaction to span multiple databases, but I want that every service method call should be in a transaction.
  Note: All my service classes have @Component and @Transactional annotation.</p>
  
  <p>Am I solving the problem in the correct way?</p>