Home > Mobile >  Multi datasource using AbstractRoutingDatasource with Spring jdbc template
Multi datasource using AbstractRoutingDatasource with Spring jdbc template

Time:11-26

I am working on a requirement for multi-tenant application which should support mulitple datasources. I have used AbstractRoutingDataSource for the JPA repositories, now I need to extend it to spring jdbc template for a new application. Is there any reference/example that can be used for reference?

CodePudding user response:

Take a look at this article. baeldung

Having configured the AbstractRoutingDataSource with the actual data source instances, it's a simple case of then wiring the AbstractRoutingDataSource into the JdbcTemplate instance and also into the TransactionManager. JdbcTemplate is thread safe and when you perform an operation against the single JdbcTemplate instance, the datasource that is used will be based on the datasource that was set on the context holder for the executing thread.

  • Related