This commit is contained in:
Wendal Chen 2019-02-26 17:17:18 +08:00
parent 210ccf710d
commit 3c035f4104

View File

@ -200,21 +200,26 @@ public class NutDaoStarter {
Matcher match = pattern.matcher(key);
if(match.find()) {
// 获取数据库名称
String name = match.group(1);
String prefix_name = "jdbc.many." + name + ".";
DataSource manyDataSource = DataSourceStarter.createDataSource(ioc, conf, prefix_name);
NutDao nutDao = new NutDao();
nutDao.setDataSource(manyDataSource);
// 处理对应的从库
String slave_prefix = prefix_name + "slave.";
DataSource slaveDataSource = DataSourceStarter.getManySlaveDataSource(ioc, conf, slave_prefix);
if(slaveDataSource != null) {
NutDaoRunner runner = new NutDaoRunner();
runner.setSlaveDataSource(slaveDataSource);
nutDao.setRunner(runner);
try {
String name = match.group(1);
String prefix_name = "jdbc.many." + name + ".";
DataSource manyDataSource = DataSourceStarter.createSlaveDataSource(ioc, conf, prefix_name);
NutDao nutDao = new NutDao();
nutDao.setDataSource(manyDataSource);
// 处理对应的从库
String slave_prefix = prefix_name + "slave.";
DataSource slaveDataSource = DataSourceStarter.getManySlaveDataSource(ioc, conf, slave_prefix);
if(slaveDataSource != null) {
NutDaoRunner runner = new NutDaoRunner();
runner.setSlaveDataSource(slaveDataSource);
nutDao.setRunner(runner);
}
// 加入到ioc对象
ioc.addBean(name + "Dao", nutDao);
}
catch (Exception e) {
throw new RuntimeException("datasource init error "+prefix_name, e);
}
// 加入到ioc对象
ioc.addBean(name + "Dao", nutDao);
}
}
}