use of com.baomidou.dynamic.datasource.DynamicRoutingDataSource in project dynamic-datasource-samples by dynamic-datasource.
the class DataSourceController method add.
/**
* 添加数据源
*/
@PostMapping("/add")
public Set<String> add(@Validated @RequestBody DataSourceDTO dto) {
DataSourceProperty dataSourceProperty = new DataSourceProperty();
BeanUtils.copyProperties(dto, dataSourceProperty);
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
DataSource dataSource = dataSourceCreator.createDataSource(dataSourceProperty);
ds.addDataSource(dto.getPoolName(), dataSource);
return ds.getDataSources().keySet();
}
use of com.baomidou.dynamic.datasource.DynamicRoutingDataSource in project dynamic-datasource-samples by dynamic-datasource.
the class MyDataSourceConfiguration method dataSource.
/**
* 将动态数据源设置为首选的
* 当spring存在多个数据源时, 自动注入的是首选的对象
* 设置为主要的数据源之后,就可以支持shardingJdbc原生的配置方式了
*/
@Primary
@Bean
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 dynamic-datasource-samples by dynamic-datasource.
the class MyDataSourceConfiguration method dataSource.
@Primary
@Bean
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 smart-cloud by smart-cloud.
the class DynamicRoutingDataSourceAutoConfiguration method dataSource.
/**
* 核心动态数据源组件
*
* @param properties 动态数据源配置属性
* @return
*/
@Bean
@ConditionalOnMissingBean
public DynamicRoutingDataSource dataSource(final DynamicDataSourceProperties properties) {
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 RuoYi-Flowable-Plus by KonBAI-Q.
the class DataBaseHelper method getDataBaseType.
/**
* 获取当前数据库类型
*/
public static DataBaseType getDataBaseType() {
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) SpringUtils.getBean(DataSource.class);
DataSource dataSource = ds.determineDataSource();
try (Connection conn = dataSource.getConnection()) {
DatabaseMetaData metaData = conn.getMetaData();
String databaseProductName = metaData.getDatabaseProductName();
return DataBaseType.find(databaseProductName);
} catch (SQLException e) {
throw new ServiceException(e.getMessage());
}
}
Aggregations