diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigProperties.java b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigProperties.java index e6c6b5266..9795c940a 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigProperties.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/NacosConfigProperties.java @@ -184,7 +184,7 @@ public class NacosConfigProperties { */ private List extConfig; - private ConfigService configService; + private static ConfigService CONFIG_SERVICE; // todo sts support @@ -402,8 +402,8 @@ public class NacosConfigProperties { public ConfigService configServiceInstance() { - if (null != configService) { - return configService; + if (null != CONFIG_SERVICE) { + return CONFIG_SERVICE; } Properties properties = new Properties(); @@ -430,8 +430,8 @@ public class NacosConfigProperties { } try { - configService = NacosFactory.createConfigService(properties); - return configService; + CONFIG_SERVICE = NacosFactory.createConfigService(properties); + return CONFIG_SERVICE; } catch (Exception e) { log.error("create config service error!properties={},e=,", this, e); diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java index 3826285fa..7f5aed3c2 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java @@ -182,9 +182,9 @@ public class NacosDiscoveryProperties { @Autowired private Environment environment; - private NamingService namingService; + private static NamingService NAMING_SERVICE; - private NamingMaintainService namingMaintainService; + private static NamingMaintainService NAMING_MAINTAIN_SERVICE; @PostConstruct public void init() throws SocketException { @@ -465,35 +465,35 @@ public class NacosDiscoveryProperties { public NamingService namingServiceInstance() { - if (null != namingService) { - return namingService; + if (null != NAMING_SERVICE) { + return NAMING_SERVICE; } try { - namingService = NacosFactory.createNamingService(getNacosProperties()); + NAMING_SERVICE = NacosFactory.createNamingService(getNacosProperties()); } catch (Exception e) { log.error("create naming service error!properties={},e=,", this, e); return null; } - return namingService; + return NAMING_SERVICE; } public NamingMaintainService namingMaintainServiceInstance() { - if (null != namingMaintainService) { - return namingMaintainService; + if (null != NAMING_MAINTAIN_SERVICE) { + return NAMING_MAINTAIN_SERVICE; } try { - namingMaintainService = NamingMaintainFactory + NAMING_MAINTAIN_SERVICE = NamingMaintainFactory .createMaintainService(getNacosProperties()); } catch (Exception e) { log.error("create naming service error!properties={},e=,", this, e); return null; } - return namingMaintainService; + return NAMING_MAINTAIN_SERVICE; } private Properties getNacosProperties() {