use of com.maxqiu.demo.system.entity.DbInfo 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());
}
Aggregations