From 2513c221e2ceb5a11cd690be60435f4723f4f51f Mon Sep 17 00:00:00 2001 From: chickenlj Date: Fri, 21 Jun 2024 16:27:09 +0800 Subject: [PATCH 1/3] fix nacos clusterName --- .../com/alibaba/cloud/nacos/NacosConfigProperties.java | 8 +++++++- .../com/alibaba/cloud/nacos/NacosDiscoveryProperties.java | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigProperties.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigProperties.java index 0044f8b1ff..b4af4aaa6a 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigProperties.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigProperties.java @@ -565,7 +565,7 @@ public Properties getConfigServiceProperties() { */ public Properties assembleConfigServiceProperties() { Properties properties = new Properties(); - properties.put(SERVER_ADDR, Objects.toString(this.serverAddr, DEFAULT_ADDRESS)); + properties.put(SERVER_ADDR, Objects.toString(this.serverAddr, "")); properties.put(USERNAME, Objects.toString(this.username, "")); properties.put(PASSWORD, Objects.toString(this.password, "")); properties.put(ENCODE, Objects.toString(this.encode, "")); @@ -591,6 +591,12 @@ public Properties assembleConfigServiceProperties() { } enrichNacosConfigProperties(properties); + + // set default value when serverAddr and endpoint is empty + if (StringUtils.isEmpty(this.serverAddr) && StringUtils.isEmpty(this.endpoint)) { + properties.put(SERVER_ADDR, DEFAULT_ADDRESS); + } + return properties; } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java index 3e385ec8d6..89e81b3955 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java @@ -134,7 +134,7 @@ public class NacosDiscoveryProperties { /** * cluster name for nacos . */ - private String clusterName = "DEFAULT"; + private String clusterName; /** * group name for nacos. @@ -692,7 +692,8 @@ public Properties getNacosProperties() { properties.put(ACCESS_KEY, accessKey); properties.put(SECRET_KEY, secretKey); - properties.put(CLUSTER_NAME, clusterName); + // only used for instance.setClusterName() +// properties.put(CLUSTER_NAME, clusterName); properties.put(NAMING_LOAD_CACHE_AT_START, namingLoadCacheAtStart); enrichNacosDiscoveryProperties(properties); From 07674baf673a43578f10d180e1bf6a523d619afa Mon Sep 17 00:00:00 2001 From: chickenlj Date: Mon, 24 Jun 2024 12:35:09 +0800 Subject: [PATCH 2/3] fix nacos config service init too early --- .../java/com/alibaba/cloud/nacos/NacosConfigManager.java | 3 --- .../cloud/nacos/refresh/NacosContextRefresher.java | 9 +++++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigManager.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigManager.java index 3a546002dd..d7f53aa0e7 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigManager.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigManager.java @@ -38,9 +38,6 @@ public class NacosConfigManager { public NacosConfigManager(NacosConfigProperties nacosConfigProperties) { this.nacosConfigProperties = nacosConfigProperties; - // Compatible with older code in NacosConfigProperties,It will be deleted in the - // future. - createConfigService(nacosConfigProperties); } /** diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/refresh/NacosContextRefresher.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/refresh/NacosContextRefresher.java index a832bb8372..c05f44b4d1 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/refresh/NacosContextRefresher.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/refresh/NacosContextRefresher.java @@ -61,7 +61,9 @@ public class NacosContextRefresher private final NacosRefreshHistory nacosRefreshHistory; - private final ConfigService configService; + private ConfigService configService; + + private NacosConfigManager configManager; private ApplicationContext applicationContext; @@ -71,9 +73,9 @@ public class NacosContextRefresher public NacosContextRefresher(NacosConfigManager nacosConfigManager, NacosRefreshHistory refreshHistory) { + this.configManager = nacosConfigManager; this.nacosConfigProperties = nacosConfigManager.getNacosConfigProperties(); this.nacosRefreshHistory = refreshHistory; - this.configService = nacosConfigManager.getConfigService(); this.isRefreshEnabled = this.nacosConfigProperties.isRefreshEnabled(); } @@ -127,6 +129,9 @@ public void innerReceive(String dataId, String group, } }); try { + if (configService == null && configManager != null) { + configService = configManager.getConfigService(); + } configService.addListener(dataKey, groupKey, listener); log.info("[Nacos Config] Listening config: dataId={}, group={}", dataKey, groupKey); From c9ede6203d003f35b74c033762035cd214616627 Mon Sep 17 00:00:00 2001 From: chickenlj Date: Fri, 29 Nov 2024 10:24:22 +0800 Subject: [PATCH 3/3] release 2021.0.6.2 --- pom.xml | 2 +- spring-cloud-alibaba-dependencies/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index fae5862df2..29d7be8811 100644 --- a/pom.xml +++ b/pom.xml @@ -80,7 +80,7 @@ - 2022.0.0.1 + 2022.0.0.2 2022.0.0 diff --git a/spring-cloud-alibaba-dependencies/pom.xml b/spring-cloud-alibaba-dependencies/pom.xml index 0e49684c13..dc73637aea 100644 --- a/spring-cloud-alibaba-dependencies/pom.xml +++ b/spring-cloud-alibaba-dependencies/pom.xml @@ -18,7 +18,7 @@ Spring Cloud Alibaba Dependencies - 2022.0.0.1 + 2022.0.0.2 1.8.8 1.8.0 2.2.3