From 3c035f410441d26abb96c0ade2a669506758a4f5 Mon Sep 17 00:00:00 2001 From: Wendal Chen Date: Tue, 26 Feb 2019 17:17:18 +0800 Subject: [PATCH] ... --- .../boot/starter/nutz/dao/NutDaoStarter.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) 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 7bcdf560..f69d0efd 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 @@ -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); } } }