use of com.baomidou.dynamic.datasource.DynamicRoutingDataSource in project jeecg-boot by jeecgboot.
the class DataSourceConfiguration method dataSource.
/**
* 将动态数据源设置为首选的
* 当spring存在多个数据源时, 自动注入的是首选的对象
* 设置为主要的数据源之后,就可以支持shardingjdbc原生的配置方式了
*
* @return
*/
@Primary
@Bean
public DataSource dataSource(DynamicDataSourceProvider dynamicDataSourceProvider) {
DynamicRoutingDataSource dataSource = new DynamicRoutingDataSource();
dataSource.setPrimary(dynamicDataSourceProperties.getPrimary());
dataSource.setStrict(dynamicDataSourceProperties.getStrict());
dataSource.setStrategy(dynamicDataSourceProperties.getStrategy());
dataSource.setProvider(dynamicDataSourceProvider);
dataSource.setP6spy(dynamicDataSourceProperties.getP6spy());
dataSource.setSeata(dynamicDataSourceProperties.getSeata());
return dataSource;
}
use of com.baomidou.dynamic.datasource.DynamicRoutingDataSource in project demo-SpringBoot by Max-Qiu.
the class ApplicationRunnerImpl method run.
@Override
public void run(ApplicationArguments args) {
List<DbInfo> list = dbInfoService.list();
for (DbInfo dbInfo : list) {
DataSourceProperty dataSourceProperty = new DataSourceProperty();
dataSourceProperty.setDriverClassName(dbInfo.getDriverClassName());
dataSourceProperty.setUrl(dbInfo.getUrl());
dataSourceProperty.setUsername(dbInfo.getUsername());
dataSourceProperty.setPassword(dbInfo.getPassword());
dataSourceProperty.setLazy(true);
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
DataSource dataSource = hikariDataSourceCreator.createDataSource(dataSourceProperty);
ds.addDataSource(dbInfo.getKey(), dataSource);
}
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
System.out.println(ds.getDataSources().keySet());
}
use of com.baomidou.dynamic.datasource.DynamicRoutingDataSource in project dynamic-datasource-spring-boot-starter by baomidou.
the class DynamicDataSourceAutoConfiguration method dataSource.
@Bean
@ConditionalOnMissingBean
public DataSource dataSource() {
DynamicRoutingDataSource dataSource = new DynamicRoutingDataSource();
dataSource.setPrimary(properties.getPrimary());
dataSource.setStrict(properties.getStrict());
dataSource.setStrategy(properties.getStrategy());
dataSource.setP6spy(properties.getP6spy());
dataSource.setSeata(properties.getSeata());
return dataSource;
}
use of com.baomidou.dynamic.datasource.DynamicRoutingDataSource in project springboot by ipcrystal.
the class DataSourceConfiguration method dataSource.
/**
* 将动态数据源设置为首选的
* 当spring存在多个数据源时, 自动注入的是首选的对象
* 设置为主要的数据源之后,就可以支持shardingjdbc原生的配置方式了
*
* @return DataSource
*/
@Primary
@Bean
public DataSource dataSource() {
DynamicRoutingDataSource dataSource = new DynamicRoutingDataSource();
dataSource.setPrimary(dynamicDataSourceProperties.getPrimary());
dataSource.setStrict(dynamicDataSourceProperties.getStrict());
dataSource.setStrategy(dynamicDataSourceProperties.getStrategy());
dataSource.setP6spy(dynamicDataSourceProperties.getP6spy());
dataSource.setSeata(dynamicDataSourceProperties.getSeata());
dataSource.addDataSource(SHARDING_DATA_SOURCE_NAME, shardingDataSource);
return dataSource;
}
use of com.baomidou.dynamic.datasource.DynamicRoutingDataSource in project dynamic-datasource-samples by dynamic-datasource.
the class DataSourceController method remove.
/**
* 删除数据源
*/
@DeleteMapping
public String remove(String name) {
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
ds.removeDataSource(name);
return "删除成功";
}
Aggregations