mirror of
https://gitee.com/nutz/nutzboot.git
synced 2024-11-30 02:38:28 +08:00
change: DataSourceStarter.createSlaveDataSource方法添加prefix参数 #116
This commit is contained in:
parent
90152b1a47
commit
46497719e1
@ -75,7 +75,7 @@ public class BeetlSqlStarter {
|
||||
public ConnectionSource createConnectionSource(@Inject DataSource dataSource) {
|
||||
DataSource[] slaves = null;
|
||||
if (Lang.loadClassQuite("org.nutz.boot.starter.jdbc.DataSourceStarter") != null) {
|
||||
DataSource slaveDataSource = DataSourceStarter.getSlaveDataSource(ioc, conf);
|
||||
DataSource slaveDataSource = DataSourceStarter.getSlaveDataSource(ioc, conf, "jdbc.slave.");
|
||||
if (slaveDataSource != null)
|
||||
slaves = new DataSource[] {slaveDataSource};
|
||||
}
|
||||
|
@ -153,18 +153,18 @@ public class DataSourceStarter {
|
||||
return new HikariDataSource(new HikariConfig(properties));
|
||||
}
|
||||
|
||||
public static DataSource getSlaveDataSource(Ioc ioc, PropertiesProxy conf) {
|
||||
public static DataSource getSlaveDataSource(Ioc ioc, PropertiesProxy conf, String prefix) {
|
||||
if (ioc.has("slaveDataSource")) {
|
||||
return ioc.get(DataSource.class, "slaveDataSource");
|
||||
} else {
|
||||
// 看看有多少从数据库被定义了
|
||||
List<DataSource> slaveDataSources = new ArrayList<>();
|
||||
for (String key : conf.keys()) {
|
||||
if (key.startsWith("jdbc.slave.") && key.endsWith(".url")) {
|
||||
String slaveName = key.substring("jdbc.slave.".length(), key.length() - ".url".length());
|
||||
if (key.startsWith(prefix) && key.endsWith(".url")) {
|
||||
String slaveName = key.substring(prefix.length(), key.length() - ".url".length());
|
||||
log.debug("found Slave DataSource name=" + slaveName);
|
||||
try {
|
||||
DataSource slaveDataSource = DataSourceStarter.createSlaveDataSource(ioc, conf, "jdbc.slave." + slaveName + ".");
|
||||
DataSource slaveDataSource = DataSourceStarter.createSlaveDataSource(ioc, conf, prefix + slaveName + ".");
|
||||
slaveDataSources.add(slaveDataSource);
|
||||
slaves.add(slaveDataSource);
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ public class NutDaoStarter {
|
||||
dao.setInterceptors(interceptors);
|
||||
// 看看是不是需要注入从数据库
|
||||
if (Lang.loadClassQuite("org.nutz.boot.starter.jdbc.DataSourceStarter") != null) {
|
||||
DataSource slaveDataSource = DataSourceStarter.getSlaveDataSource(ioc, conf);
|
||||
DataSource slaveDataSource = DataSourceStarter.getSlaveDataSource(ioc, conf, "jdbc.slave.");
|
||||
if (slaveDataSource != null) {
|
||||
NutDaoRunner runner = new NutDaoRunner();
|
||||
runner.setSlaveDataSource(slaveDataSource);
|
||||
|
Loading…
Reference in New Issue
Block a user