加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
multi-datasource.md 982 Bytes
一键复制 编辑 原始数据 按行查看 历史
change 提交于 2024-02-01 08:42 . [new]update version and readme
@Configuration
public class DbConfig {
    @Bean(name = "dataSource")
    @Primary
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource mainDataSource() {
        return DataSourceBuilder.create().build();
    }
    
    @Bean(name = "orderDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.order")
    public DataSource oldDataSource() {
        return DataSourceBuilder.create().build();
    }
    
    @Bean("dataSourceWrapper")
    public DataSourceWrapper dataSourceWrapper(@Qualifier("dataSource")DataSource dataSource) {
        return new DataSourceWrapper(dataSource,"dataSource");
    }
 

    @Bean("orderDataSourceWrapper")
    public DataSourceWrapper oldDataSourceWrapper(@Qualifier("orderDataSource")DataSource dataSource) {
        return new DataSourceWrapper(dataSource,"orderDataSource");
    }

}
@DataSourceKey("orderDataSource")
public interface OrderQueryDao extends QueryRepository {
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化