mirror of
https://gitee.com/nutz/nutzboot.git
synced 2024-11-30 02:38:28 +08:00
add: 新增多数据库支持
This commit is contained in:
parent
cb6355c49a
commit
6fbb76e1f8
@ -5,6 +5,7 @@ import java.util.List;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import org.nutz.boot.annotation.PropDoc;
|
||||
import org.nutz.boot.starter.jdbc.DataSourceStarter;
|
||||
import org.nutz.dao.SqlManager;
|
||||
@ -182,9 +183,29 @@ public class NutDaoStarter {
|
||||
dao.setRunner(runner);
|
||||
}
|
||||
}
|
||||
injectManyDao();
|
||||
return dao;
|
||||
}
|
||||
|
||||
private void injectManyDao() {
|
||||
if(conf.containsKey("jdbc.many.names")) {
|
||||
String names = conf.get("jdbc.many.names");
|
||||
for(String name : names.split(",")) {
|
||||
String prefix_name = "jdbc.many." + name + ".";
|
||||
DataSource manyDataSource = conf.make(DruidDataSource.class, prefix_name);
|
||||
NutDao nutDao = new NutDao();
|
||||
nutDao.setDataSource(manyDataSource);
|
||||
|
||||
String slave_prefix = prefix_name + "slave.";
|
||||
DataSource slaveDataSource = DataSourceStarter.getSlaveDataSource(ioc, conf, slave_prefix);
|
||||
NutDaoRunner runner = new NutDaoRunner();
|
||||
runner.setSlaveDataSource(slaveDataSource);
|
||||
nutDao.setRunner(runner);
|
||||
ioc.addBean(name+"Dao", nutDao);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回值不能是CacheManager,因为要考虑没有加ehcache的情况
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user