I am using JdbcTemplate in my Project and we have requirement of implementing multi tenancy in our project.
Right now we are just creating a bean of DataSource and then injecting that datasource to jdbtemplate like
@Bean
public DataSource dataSource() {
final JndiDataSourceLookup dsLookup = new JndiDataSourceLookup();
dsLookup.setResourceRef(true);
return dsLookup.getDataSource("path");
}
@Bean
public NamedParameterJdbcTemplate jdbcTemplate(DataSource dataSource) {
JdbcTemplate template = new JdbcTemplate(dataSource);
return new NamedParameterJdbcTemplate(template);
}
But after having multi tenancy we need to connect to the different schema according to the parameter in the request.
Can anyone tell how i can do this with jdbctemplate?