Skip to content

Latest commit

 

History

History
36 lines (29 loc) · 982 Bytes

multi-datasource.md

File metadata and controls

36 lines (29 loc) · 982 Bytes
@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 {
}