【发布时间】:2021-02-15 02:08:22
【问题描述】:
我在我的项目中使用 JdbcTemplate,我们需要在我们的项目中实现多租户。
现在我们只是创建一个 DataSource 的 bean,然后将该数据源注入到 jdbtemplate 中
@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);
}
但是在多租户之后,我们需要根据请求中的参数连接到不同的架构。
谁能告诉我如何用 jdbctemplate 做到这一点?
【问题讨论】:
标签: spring spring-boot spring-jdbc jdbctemplate