From 8aa31dc33e1b1902bff7ece0f7f07dc1cc3498c2 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Thu, 22 Sep 2022 00:55:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96string=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96=E7=9A=84=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../parser/nacos/util/NacosParserHelper.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/liteflow-rule-plugin/liteflow-rule-nacos/src/main/java/com/yomahub/liteflow/parser/nacos/util/NacosParserHelper.java b/liteflow-rule-plugin/liteflow-rule-nacos/src/main/java/com/yomahub/liteflow/parser/nacos/util/NacosParserHelper.java index 2c7f4642e..10f8d3c33 100644 --- a/liteflow-rule-plugin/liteflow-rule-nacos/src/main/java/com/yomahub/liteflow/parser/nacos/util/NacosParserHelper.java +++ b/liteflow-rule-plugin/liteflow-rule-nacos/src/main/java/com/yomahub/liteflow/parser/nacos/util/NacosParserHelper.java @@ -7,6 +7,7 @@ import com.alibaba.nacos.client.config.NacosConfigService; import com.yomahub.liteflow.exception.ParseException; import com.yomahub.liteflow.parser.nacos.exception.NacosException; import com.yomahub.liteflow.parser.nacos.vo.NacosParserVO; +import com.yomahub.liteflow.spi.holder.ContextAwareHolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,17 +27,20 @@ public class NacosParserHelper { private final NacosParserVO nacosParserVO; - private final NacosConfigService configService; + private NacosConfigService configService; public NacosParserHelper(NacosParserVO nacosParserVO) { this.nacosParserVO = nacosParserVO; try{ - Properties properties = new Properties(); - properties.put(PropertyKeyConst.SERVER_ADDR, nacosParserVO.getServerAddr()); - properties.put(PropertyKeyConst.NAMESPACE,nacosParserVO.getNamespace()); - properties.put(PropertyKeyConst.USERNAME,nacosParserVO.getUsername()); - properties.put(PropertyKeyConst.PASSWORD,nacosParserVO.getPassword()); - this.configService = new NacosConfigService(properties); + this.configService = ContextAwareHolder.loadContextAware().getBean(NacosConfigService.class); + if (this.configService == null){ + Properties properties = new Properties(); + properties.put(PropertyKeyConst.SERVER_ADDR, nacosParserVO.getServerAddr()); + properties.put(PropertyKeyConst.NAMESPACE,nacosParserVO.getNamespace()); + properties.put(PropertyKeyConst.USERNAME,nacosParserVO.getUsername()); + properties.put(PropertyKeyConst.PASSWORD,nacosParserVO.getPassword()); + this.configService = new NacosConfigService(properties); + } }catch (Exception e){ throw new NacosException(e.getMessage()); } @@ -55,7 +59,7 @@ public class NacosParserHelper { */ public void checkContent(String content) { if (StrUtil.isBlank(content)) { - String error = MessageFormat.format("the node[{0}] value is empty", nacosParserVO.toString()); + String error = StrUtil.format("the node[{}] value is empty", nacosParserVO.toString()); throw new ParseException(error); } }