From e9b8eecc762bdd4b4dd72e9844517ed21c2a58dc Mon Sep 17 00:00:00 2001 From: wentao Date: Thu, 7 Mar 2019 14:47:26 +0800 Subject: [PATCH] =?UTF-8?q?-=20add:=20=E5=A2=9E=E5=8A=A0Nacos=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E9=A1=B9=E5=AE=8C=E6=95=B4=E5=BA=A6=E5=88=A4=E6=96=AD?= =?UTF-8?q?=EF=BC=8C=E5=A6=82=E6=9E=9C=E9=85=8D=E7=BD=AE=E4=B8=8D=E5=AE=8C?= =?UTF-8?q?=E6=95=B4=EF=BC=8C=E5=88=99=E8=B7=B3=E8=BF=87=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../starter/nacos/NacosConfigureStarter.java | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/nutzboot-starter/nutzboot-starter-nacos-config-client/src/main/java/org/nutz/boot/starter/nacos/NacosConfigureStarter.java b/nutzboot-starter/nutzboot-starter-nacos-config-client/src/main/java/org/nutz/boot/starter/nacos/NacosConfigureStarter.java index 02110d90..5fb39b0e 100644 --- a/nutzboot-starter/nutzboot-starter-nacos-config-client/src/main/java/org/nutz/boot/starter/nacos/NacosConfigureStarter.java +++ b/nutzboot-starter/nutzboot-starter-nacos-config-client/src/main/java/org/nutz/boot/starter/nacos/NacosConfigureStarter.java @@ -72,28 +72,32 @@ public class NacosConfigureStarter implements ServerFace { String group = conf.get(NACOS_GROUP); String dataType = conf.get(NACOS_DATA_TYPE); - Properties properties = new Properties(); - properties.put("serverAddr", serverAddr); - ConfigService configService = NacosFactory.createConfigService(properties); - String configInfo = configService.getConfig(dataId, group, 5000); - log.debugf("get nacos config:%s", configInfo); - if (Strings.isNotBlank(configInfo)) { - setConfig(configInfo, dataType); - } - configService.addListener(dataId, group, new Listener() { - @Override - public void receiveConfigInfo(String configInfo) { - log.debugf("receive nacos server config:%s", configInfo); - if (Strings.isNotBlank(configInfo)) { - setConfig(configInfo, dataType); + if(Strings.isBlank(serverAddr) || Strings.isBlank(dataId) || Strings.isBlank(group) || Strings.isBlank(dataType)) { + log.debugf("nacos server config is not found or incomplete, skip..."); + } else { + Properties properties = new Properties(); + properties.put("serverAddr", serverAddr); + ConfigService configService = NacosFactory.createConfigService(properties); + String configInfo = configService.getConfig(dataId, group, 5000); + log.debugf("get nacos config:%s", configInfo); + if (Strings.isNotBlank(configInfo)) { + setConfig(configInfo, dataType); + } + configService.addListener(dataId, group, new Listener() { + @Override + public void receiveConfigInfo(String configInfo) { + log.debugf("receive nacos server config:%s", configInfo); + if (Strings.isNotBlank(configInfo)) { + setConfig(configInfo, dataType); + } } - } - @Override - public Executor getExecutor() { - return null; - } - }); + @Override + public Executor getExecutor() { + return null; + } + }); + } } private void setConfig(String content, String contentType) {