use of com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties in project jeecg-boot by jeecgboot.
the class CommonUtils method getDataSourceProperty.
/**
* 根据数据源key获取DataSourceProperty
* @param sourceKey
* @return
*/
public static DataSourceProperty getDataSourceProperty(String sourceKey) {
DynamicDataSourceProperties prop = SpringContextUtils.getApplicationContext().getBean(DynamicDataSourceProperties.class);
Map<String, DataSourceProperty> map = prop.getDatasource();
DataSourceProperty db = (DataSourceProperty) map.get(sourceKey);
return db;
}
use of com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties in project jeecg-boot by jeecgboot.
the class CommonUtils method getDataSourceConnect.
/**
* 根据sourceKey 获取数据源连接
* @param sourceKey
* @return
* @throws SQLException
*/
public static Connection getDataSourceConnect(String sourceKey) throws SQLException {
if (oConvertUtils.isEmpty(sourceKey)) {
sourceKey = "master";
}
DynamicDataSourceProperties prop = SpringContextUtils.getApplicationContext().getBean(DynamicDataSourceProperties.class);
Map<String, DataSourceProperty> map = prop.getDatasource();
DataSourceProperty db = (DataSourceProperty) map.get(sourceKey);
if (db == null) {
return null;
}
DriverManagerDataSource ds = new DriverManagerDataSource();
ds.setDriverClassName(db.getDriverClassName());
ds.setUrl(db.getUrl());
ds.setUsername(db.getUsername());
ds.setPassword(db.getPassword());
return ds.getConnection();
}
Aggregations