From 46497719e150e6bb46a262a5acff587be694a239 Mon Sep 17 00:00:00 2001 From: Wendal Chen Date: Sun, 28 Jan 2018 17:53:40 +0800 Subject: [PATCH] =?UTF-8?q?change:=20DataSourceStarter.createSlaveDataSour?= =?UTF-8?q?ce=E6=96=B9=E6=B3=95=E6=B7=BB=E5=8A=A0prefix=E5=8F=82=E6=95=B0?= =?UTF-8?q?=20#116?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/nutz/boot/starter/beetlsql/BeetlSqlStarter.java | 2 +- .../org/nutz/boot/starter/jdbc/DataSourceStarter.java | 8 ++++---- .../org/nutz/boot/starter/nutz/dao/NutDaoStarter.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nutzboot-starter/nutzboot-starter-beetlsql/src/main/java/org/nutz/boot/starter/beetlsql/BeetlSqlStarter.java b/nutzboot-starter/nutzboot-starter-beetlsql/src/main/java/org/nutz/boot/starter/beetlsql/BeetlSqlStarter.java index 83d79a55..4084e298 100644 --- a/nutzboot-starter/nutzboot-starter-beetlsql/src/main/java/org/nutz/boot/starter/beetlsql/BeetlSqlStarter.java +++ b/nutzboot-starter/nutzboot-starter-beetlsql/src/main/java/org/nutz/boot/starter/beetlsql/BeetlSqlStarter.java @@ -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}; } diff --git a/nutzboot-starter/nutzboot-starter-jdbc/src/main/java/org/nutz/boot/starter/jdbc/DataSourceStarter.java b/nutzboot-starter/nutzboot-starter-jdbc/src/main/java/org/nutz/boot/starter/jdbc/DataSourceStarter.java index 8257ae2f..2086a9a8 100644 --- a/nutzboot-starter/nutzboot-starter-jdbc/src/main/java/org/nutz/boot/starter/jdbc/DataSourceStarter.java +++ b/nutzboot-starter/nutzboot-starter-jdbc/src/main/java/org/nutz/boot/starter/jdbc/DataSourceStarter.java @@ -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 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); } diff --git a/nutzboot-starter/nutzboot-starter-nutz-dao/src/main/java/org/nutz/boot/starter/nutz/dao/NutDaoStarter.java b/nutzboot-starter/nutzboot-starter-nutz-dao/src/main/java/org/nutz/boot/starter/nutz/dao/NutDaoStarter.java index 12e44f31..9d91578b 100644 --- a/nutzboot-starter/nutzboot-starter-nutz-dao/src/main/java/org/nutz/boot/starter/nutz/dao/NutDaoStarter.java +++ b/nutzboot-starter/nutzboot-starter-nutz-dao/src/main/java/org/nutz/boot/starter/nutz/dao/NutDaoStarter.java @@ -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);