1、添加请求对应的数据源标签
DynamicDataSourceContextHolder.push(ds);
2、添加数据源
3、动态添加数据源
private DynamicRoutingDataSource dataSource; private DefaultDataSourceCreator dataSourceCreator; //创建数据源 DataSourceProperty dataSourceProperty = new DataSourceProperty(); dataSourceProperty.setUrl(dbInfo.getDbUrl()); dataSourceProperty.setUsername(dbInfo.getDbUsername()); dataSourceProperty.setPassword(dbInfo.getDbPassword()); dataSourceProperty.setDriverClassName("com.mysql.cj.jdbc.Driver"); dataSourceProperty.setDruid(new DruidConfig()); return this.dataSourceCreator.createDataSource(dataSourceProperty); //动态添加数据源 this.dataSource.addDataSource(tenantId, dataSource);
标签:dataSourceProperty,数据源,Dynamic,dbInfo,添加,Datasource,动态,dataSource From: https://www.cnblogs.com/raorao1994/p/18195582