From b73aa9c54bf95453a1c313e4c8c8f92680708467 Mon Sep 17 00:00:00 2001 From: 3y Date: Thu, 23 Mar 2023 21:04:35 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BC=98=E5=8C=96nacos=E6=B3=A8?= =?UTF-8?q?=E5=85=A5ConfigService=E5=AF=B9=E8=B1=A1=202=E3=80=81=E5=8D=87?= =?UTF-8?q?=E7=BA=A7apollo-client=E5=8C=85=EF=BC=88=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E4=B8=8D=E6=94=AF=E6=8C=81JDK8=E4=BB=A5=E4=B8=8A=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- austin-support/pom.xml | 2 +- .../austin/support/utils/NacosUtils.java | 24 ++++++------------- .../src/main/resources/application.properties | 9 +++---- pom.xml | 4 ++-- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/austin-support/pom.xml b/austin-support/pom.xml index c091f98..044423a 100644 --- a/austin-support/pom.xml +++ b/austin-support/pom.xml @@ -75,7 +75,7 @@ com.ctrip.framework.apollo - apollo-client-config-data + apollo-client diff --git a/austin-support/src/main/java/com/java3y/austin/support/utils/NacosUtils.java b/austin-support/src/main/java/com/java3y/austin/support/utils/NacosUtils.java index 4437659..1dc6ee0 100644 --- a/austin-support/src/main/java/com/java3y/austin/support/utils/NacosUtils.java +++ b/austin-support/src/main/java/com/java3y/austin/support/utils/NacosUtils.java @@ -1,8 +1,8 @@ package com.java3y.austin.support.utils; import cn.hutool.core.util.StrUtil; -import com.alibaba.nacos.api.NacosFactory; -import com.alibaba.nacos.api.PropertyKeyConst; +import com.alibaba.nacos.api.annotation.NacosInjected; +import com.alibaba.nacos.api.config.ConfigService; import com.alibaba.nacos.api.exception.NacosException; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.exception.ExceptionUtils; @@ -22,19 +22,14 @@ import java.util.Properties; @Slf4j @Component public class NacosUtils { - @Value("${austin.nacos.server}") - private String nacosServer; - @Value("${austin.nacos.username}") - private String nacosUsername; - @Value("${austin.nacos.password}") - private String nacosPassword; + @NacosInjected + private ConfigService configService; + @Value("${austin.nacos.group}") private String nacosGroup; @Value("${austin.nacos.dataId}") private String nacosDataId; - @Value("${austin.nacos.namespace}") - private String nacosNamespace; - private final Properties request = new Properties(); + private final Properties properties = new Properties(); public String getProperty(String key, String defaultValue) { @@ -53,12 +48,7 @@ public class NacosUtils { private String getContext() { String context = null; try { - request.put(PropertyKeyConst.SERVER_ADDR, nacosServer); - request.put(PropertyKeyConst.NAMESPACE, nacosNamespace); - request.put(PropertyKeyConst.USERNAME, nacosUsername); - request.put(PropertyKeyConst.PASSWORD, nacosPassword); - context = NacosFactory.createConfigService(request) - .getConfig(nacosDataId, nacosGroup, 5000); + context = configService.getConfig(nacosDataId, nacosGroup, 5000); } catch (NacosException e) { log.error("Nacos error:{}", ExceptionUtils.getStackTrace(e)); } diff --git a/austin-web/src/main/resources/application.properties b/austin-web/src/main/resources/application.properties index af996f3..5a2ee21 100644 --- a/austin-web/src/main/resources/application.properties +++ b/austin-web/src/main/resources/application.properties @@ -77,12 +77,13 @@ apollo.bootstrap.namespaces=boss.austin,dynamic-tp-apollo-dtp.yml ########################################## apollo end ########################################## ########################################## nacos start ########################################## -austin.nacos.server=austin.nacos:8848 -austin.nacos.username=nacos -austin.nacos.password=nacos +nacos.config.server-addr=austin.nacos:8848 +nacos.config.username=nacos +nacos.config.password=nacos +nacos.config.namespace=9537c674-f3a6-4203-b286-ef0c36bfacb2 + austin.nacos.dataId=austin austin.nacos.group=DEFAULT_GROUP -austin.nacos.namespace=9537c674-f3a6-4203-b286-ef0c36bfacb2 nacos.config.enabled=${austin.nacos.enabled} ########################################## nacos end ########################################## diff --git a/pom.xml b/pom.xml index 387a092..1208e46 100644 --- a/pom.xml +++ b/pom.xml @@ -95,8 +95,8 @@ com.ctrip.framework.apollo - apollo-client-config-data - 1.9.1 + apollo-client + 2.1.0