From 5445742a7ed3da693fe61fb8101e8d98da04c28a Mon Sep 17 00:00:00 2001 From: Giorno Date: Fri, 22 Jul 2022 15:39:17 +0800 Subject: [PATCH] feat:nacos --- .../java3y/austin/support/service/ConfigService.java | 4 ++-- .../support/service/impl/ConfigServiceImpl.java | 11 +++++++++++ austin-web/src/main/resources/application.properties | 4 ++++ pom.xml | 1 - 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/austin-support/src/main/java/com/java3y/austin/support/service/ConfigService.java b/austin-support/src/main/java/com/java3y/austin/support/service/ConfigService.java index 29b37f2..b73e09a 100644 --- a/austin-support/src/main/java/com/java3y/austin/support/service/ConfigService.java +++ b/austin-support/src/main/java/com/java3y/austin/support/service/ConfigService.java @@ -10,8 +10,8 @@ public interface ConfigService { /** * 读取配置 - * 1、当启动使用了apollo,优先读取apollo - * 2、当没有启动apollo,读取本地 local.properties 配置文件的内容 + * 1、当启动使用了apollo或者nacos,优先读取远程配置 + * 2、当没有启动远程配置,读取本地 local.properties 配置文件的内容 * @param key * @param defaultValue * @return diff --git a/austin-support/src/main/java/com/java3y/austin/support/service/impl/ConfigServiceImpl.java b/austin-support/src/main/java/com/java3y/austin/support/service/impl/ConfigServiceImpl.java index 860e84e..509cac0 100644 --- a/austin-support/src/main/java/com/java3y/austin/support/service/impl/ConfigServiceImpl.java +++ b/austin-support/src/main/java/com/java3y/austin/support/service/impl/ConfigServiceImpl.java @@ -5,8 +5,10 @@ import cn.hutool.setting.dialect.Props; import com.ctrip.framework.apollo.Config; import com.java3y.austin.support.service.ConfigService; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.stereotype.Service; +import javax.annotation.Resource; import java.nio.charset.StandardCharsets; @@ -30,12 +32,21 @@ public class ConfigServiceImpl implements ConfigService { private Boolean enableApollo; @Value("${apollo.bootstrap.namespaces}") private String namespaces; + /** + * nacos配置 + */ + @Value("${austin.nacos.enabled}") + private Boolean enableNacos; + @Resource + private ConfigurableApplicationContext configurableApplicationContext; @Override public String getProperty(String key, String defaultValue) { if (enableApollo) { Config config = com.ctrip.framework.apollo.ConfigService.getConfig(namespaces.split(StrUtil.COMMA)[0]); return config.getProperty(key, defaultValue); + } else if (enableNacos) { + return configurableApplicationContext.getEnvironment().getProperty(key, defaultValue); } else { return props.getProperty(key, defaultValue); } diff --git a/austin-web/src/main/resources/application.properties b/austin-web/src/main/resources/application.properties index b0c7700..cc02ddb 100644 --- a/austin-web/src/main/resources/application.properties +++ b/austin-web/src/main/resources/application.properties @@ -128,6 +128,10 @@ app.id=austin apollo.bootstrap.enabled=${apollo.enabled} apollo.bootstrap.namespaces=boss.austin,dynamic-tp-apollo-dtp.yml +##################### nacos ##################### +austin.nacos.enabled=false + + ##################### httpUtils properties ##################### ok.http.connect-timeout=30 ok.http.keep-alive-duration=300 diff --git a/pom.xml b/pom.xml index b558b4e..8fca343 100644 --- a/pom.xml +++ b/pom.xml @@ -212,5 +212,4 @@ -