From e31a2beca473369bba7a6667bfd81e5154810528 Mon Sep 17 00:00:00 2001 From: wangjx <1609724385@qq.com> Date: Fri, 25 Jun 2021 23:28:05 +0800 Subject: [PATCH] =?UTF-8?q?nacos=E6=8C=81=E4=B9=85=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sentinel-dashboard/pom.xml | 5 +++-- .../csp/sentinel/dashboard/config/NacosConfiguration.java | 5 ++--- ...cosPropertiesConfiguration.java => NacosProperties.java} | 6 +----- .../csp/sentinel/dashboard/rule/FlowRuleNacosProvider.java | 6 +++--- .../csp/sentinel/dashboard/rule/FlowRuleNacosPublisher.java | 6 +++--- 5 files changed, 12 insertions(+), 16 deletions(-) rename sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/{NacosPropertiesConfiguration.java => NacosProperties.java} (89%) diff --git a/sentinel-dashboard/pom.xml b/sentinel-dashboard/pom.xml index 3e3fb417..3a39e453 100755 --- a/sentinel-dashboard/pom.xml +++ b/sentinel-dashboard/pom.xml @@ -135,11 +135,12 @@ 1.16.1 test - + diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/NacosConfiguration.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/NacosConfiguration.java index 7843444f..3b3d9503 100644 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/NacosConfiguration.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/NacosConfiguration.java @@ -31,10 +31,9 @@ import java.util.List; import java.util.Properties; @Configuration -@EnableConfigurationProperties(NacosConfigurationProperties.class) +@EnableConfigurationProperties(NacosProperties.class) public class NacosConfiguration { - @Bean public Converter, String> flowRuleEntityEncoder() { return JSON::toJSONString; @@ -46,7 +45,7 @@ public class NacosConfiguration { } @Bean - public ConfigService nacosConfiguration(NacosPropertiesConfiguration nacosPropertiesConfiguration) throws NacosException { + public ConfigService nacosConfiguration(NacosProperties nacosPropertiesConfiguration) throws NacosException { Properties properties = new Properties(); properties.put(PropertyKeyConst.SERVER_ADDR,nacosPropertiesConfiguration.getServerAddr()); properties.put(PropertyKeyConst.NAMESPACE,nacosPropertiesConfiguration.getNamespace()); diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/NacosPropertiesConfiguration.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/NacosProperties.java similarity index 89% rename from sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/NacosPropertiesConfiguration.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/NacosProperties.java index 9f9c51ba..11a6edda 100644 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/NacosPropertiesConfiguration.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/NacosProperties.java @@ -15,17 +15,13 @@ */ package com.alibaba.csp.sentinel.dashboard.config; -import org.springframework.beans.factory.annotation.Configurable; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; /** * @author King Wang */ -@Component -@Configurable @ConfigurationProperties(prefix="sentinel.nacos") -public class NacosPropertiesConfiguration { +public class NacosProperties { private String serverAddr; private String dataId; diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/FlowRuleNacosProvider.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/FlowRuleNacosProvider.java index bdf8284c..19b5a882 100644 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/FlowRuleNacosProvider.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/FlowRuleNacosProvider.java @@ -16,7 +16,7 @@ package com.alibaba.csp.sentinel.dashboard.rule; import com.alibaba.csp.sentinel.dashboard.common.NacosConstants; -import com.alibaba.csp.sentinel.dashboard.config.NacosPropertiesConfiguration; +import com.alibaba.csp.sentinel.dashboard.config.NacosProperties; import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; import com.alibaba.csp.sentinel.datasource.Converter; import com.alibaba.nacos.api.config.ConfigService; @@ -37,14 +37,14 @@ public class FlowRuleNacosProvider implements DynamicRuleProvider> converter; @Override public List getRules(String appName) throws Exception { String dataId=new StringBuilder(appName).append(NacosConstants.DATA_ID_POSTFIX).toString(); - String rules = configService.getConfig(dataId,nacosPropertiesConfiguration.getGroupId(),3000); + String rules = configService.getConfig(dataId,nacosProperties.getGroupId(),3000); //log.info("pull FlowRule from nacos Config:"+rules); if (rules.isEmpty()) { return new ArrayList<>(); diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/FlowRuleNacosPublisher.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/FlowRuleNacosPublisher.java index a89e06fa..a779ae02 100644 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/FlowRuleNacosPublisher.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/FlowRuleNacosPublisher.java @@ -16,7 +16,7 @@ package com.alibaba.csp.sentinel.dashboard.rule; import com.alibaba.csp.sentinel.dashboard.common.NacosConstants; -import com.alibaba.csp.sentinel.dashboard.config.NacosPropertiesConfiguration; +import com.alibaba.csp.sentinel.dashboard.config.NacosProperties; import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; import com.alibaba.csp.sentinel.datasource.Converter; import com.alibaba.csp.sentinel.util.AssertUtil; @@ -37,7 +37,7 @@ public class FlowRuleNacosPublisher implements DynamicRulePublisher,String> converter; @@ -49,6 +49,6 @@ public class FlowRuleNacosPublisher implements DynamicRulePublisher