From 9860c5ac8e962d4547b38d9c41dc9a95a1a86263 Mon Sep 17 00:00:00 2001 From: flystar32 Date: Mon, 11 Mar 2019 11:09:44 +0800 Subject: [PATCH 1/3] nacos discovery endpoint support spring.cloud.nacos.discovery.enabled , Polish #411 --- .../discovery/NacosDiscoveryClientAutoConfiguration.java | 2 ++ .../META-INF/additional-spring-configuration-metadata.json | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/org/springframework/cloud/alibaba/nacos/discovery/NacosDiscoveryClientAutoConfiguration.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/org/springframework/cloud/alibaba/nacos/discovery/NacosDiscoveryClientAutoConfiguration.java index 5fe818b36..29858fb76 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/org/springframework/cloud/alibaba/nacos/discovery/NacosDiscoveryClientAutoConfiguration.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/org/springframework/cloud/alibaba/nacos/discovery/NacosDiscoveryClientAutoConfiguration.java @@ -18,6 +18,7 @@ package org.springframework.cloud.alibaba.nacos.discovery; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.alibaba.nacos.ConditionalOnNacosDiscoveryEnabled; import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties; @@ -33,6 +34,7 @@ import org.springframework.context.annotation.Configuration; @Configuration @ConditionalOnNacosDiscoveryEnabled @EnableConfigurationProperties +@ConditionalOnProperty(value = "spring.cloud.nacos.discovery.enabled", matchIfMissing = true) @AutoConfigureBefore({ SimpleDiscoveryClientAutoConfiguration.class, CommonsClientAutoConfiguration.class }) public class NacosDiscoveryClientAutoConfiguration { diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-alibaba-nacos-discovery/src/main/resources/META-INF/additional-spring-configuration-metadata.json index d0e82a51e..75e8abd44 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-cloud-alibaba-nacos-discovery/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -5,6 +5,12 @@ "defaultValue": "${spring.application.name}", "description": "the service name to register, default value is ${spring.application.name}." }, + { + "name": "spring.cloud.nacos.discovery.enabled", + "type": "java.lang.Boolean", + "defaultValue": true, + "description": "enable nacos discovery or not." + }, { "name": "spring.cloud.nacos.discovery.namingLoadCacheAtStart", "type": "java.lang.Boolean", From 4d2de76e4be5eded12833556d1042c61e00cf03c Mon Sep 17 00:00:00 2001 From: flystar32 Date: Mon, 11 Mar 2019 11:32:57 +0800 Subject: [PATCH 2/3] support spring cloud nacos config enabled , Polish #411 --- .../cloud/alibaba/nacos/NacosConfigAutoConfiguration.java | 2 ++ .../cloud/alibaba/nacos/NacosConfigBootstrapConfiguration.java | 2 +- .../nacos/endpoint/NacosConfigEndpointAutoConfiguration.java | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/NacosConfigAutoConfiguration.java b/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/NacosConfigAutoConfiguration.java index 3833293e0..caacccd8e 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/NacosConfigAutoConfiguration.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/NacosConfigAutoConfiguration.java @@ -17,6 +17,7 @@ package org.springframework.cloud.alibaba.nacos; import org.springframework.beans.factory.BeanFactoryUtils; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.cloud.alibaba.nacos.refresh.NacosContextRefresher; import org.springframework.cloud.alibaba.nacos.refresh.NacosRefreshHistory; import org.springframework.cloud.alibaba.nacos.refresh.NacosRefreshProperties; @@ -28,6 +29,7 @@ import org.springframework.context.annotation.Configuration; * @author juven.xuxb */ @Configuration +@ConditionalOnProperty(name = "spring.cloud.nacos.config.enabled", matchIfMissing = true) public class NacosConfigAutoConfiguration { @Bean diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/NacosConfigBootstrapConfiguration.java b/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/NacosConfigBootstrapConfiguration.java index 94933a4d2..5a6ad2bbb 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/NacosConfigBootstrapConfiguration.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/NacosConfigBootstrapConfiguration.java @@ -26,6 +26,7 @@ import org.springframework.context.annotation.Configuration; * @author xiaojing */ @Configuration +@ConditionalOnProperty(name = "spring.cloud.nacos.config.enabled", matchIfMissing = true) public class NacosConfigBootstrapConfiguration { @Bean @@ -35,7 +36,6 @@ public class NacosConfigBootstrapConfiguration { } @Bean - @ConditionalOnProperty(name = "spring.cloud.nacos.config.enabled", matchIfMissing = true) public NacosPropertySourceLocator nacosPropertySourceLocator( NacosConfigProperties nacosConfigProperties) { return new NacosPropertySourceLocator(nacosConfigProperties); diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/endpoint/NacosConfigEndpointAutoConfiguration.java b/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/endpoint/NacosConfigEndpointAutoConfiguration.java index e853546d6..21d77f7fb 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/endpoint/NacosConfigEndpointAutoConfiguration.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/endpoint/NacosConfigEndpointAutoConfiguration.java @@ -21,6 +21,7 @@ import org.springframework.boot.actuate.autoconfigure.endpoint.condition.Conditi import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.cloud.alibaba.nacos.NacosConfigProperties; import org.springframework.cloud.alibaba.nacos.refresh.NacosRefreshHistory; @@ -31,6 +32,7 @@ import org.springframework.context.annotation.Bean; */ @ConditionalOnWebApplication @ConditionalOnClass(value = Endpoint.class) +@ConditionalOnProperty(name = "spring.cloud.nacos.config.enabled", matchIfMissing = true) public class NacosConfigEndpointAutoConfiguration { @Autowired From 5923f41facfdac3e6186888f7b229bc004be00b9 Mon Sep 17 00:00:00 2001 From: flystar32 Date: Mon, 11 Mar 2019 16:38:57 +0800 Subject: [PATCH 3/3] delete useless field and add additional configuration metadata --- .../alibaba/nacos/NacosConfigProperties.java | 35 +++++-------------- ...itional-spring-configuration-metadata.json | 6 ++++ 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/NacosConfigProperties.java b/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/NacosConfigProperties.java index 666051459..1518dcff1 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/NacosConfigProperties.java +++ b/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/NacosConfigProperties.java @@ -55,11 +55,6 @@ public class NacosConfigProperties { private static final Logger log = LoggerFactory .getLogger(NacosConfigProperties.class); - /** - * whether to enable nacos config. - */ - private boolean enabled = true; - /** * nacos config server address */ @@ -140,19 +135,8 @@ public class NacosConfigProperties { private ConfigService configService; - @Autowired - private Environment environment; - // todo sts support - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - public String getServerAddr() { return serverAddr; } @@ -322,16 +306,15 @@ public class NacosConfigProperties { @Override public String toString() { - return "NacosConfigProperties{" + "enabled=" + enabled + ", serverAddr='" - + serverAddr + '\'' + ", encode='" + encode + '\'' + ", group='" + group - + '\'' + ", prefix='" + prefix + '\'' + ", fileExtension='" - + fileExtension + '\'' + ", timeout=" + timeout + ", endpoint='" - + endpoint + '\'' + ", namespace='" + namespace + '\'' + ", accessKey='" - + accessKey + '\'' + ", secretKey='" + secretKey + '\'' - + ", contextPath='" + contextPath + '\'' + ", clusterName='" + clusterName - + '\'' + ", name='" + name + '\'' + ", sharedDataids='" + sharedDataids - + '\'' + ", refreshableDataids='" + refreshableDataids + '\'' - + ", extConfig=" + extConfig + '}'; + return "NacosConfigProperties{" + "serverAddr='" + serverAddr + '\'' + + ", encode='" + encode + '\'' + ", group='" + group + '\'' + ", prefix='" + + prefix + '\'' + ", fileExtension='" + fileExtension + '\'' + + ", timeout=" + timeout + ", endpoint='" + endpoint + '\'' + + ", namespace='" + namespace + '\'' + ", accessKey='" + accessKey + '\'' + + ", secretKey='" + secretKey + '\'' + ", contextPath='" + contextPath + + '\'' + ", clusterName='" + clusterName + '\'' + ", name='" + name + '\'' + + ", sharedDataids='" + sharedDataids + '\'' + ", refreshableDataids='" + + refreshableDataids + '\'' + ", extConfig=" + extConfig + '}'; } public ConfigService configServiceInstance() { diff --git a/spring-cloud-alibaba-nacos-config/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-alibaba-nacos-config/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 3ce2a169d..597126e8e 100644 --- a/spring-cloud-alibaba-nacos-config/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-cloud-alibaba-nacos-config/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -32,6 +32,12 @@ "name": "spring.cloud.nacos.config.ext-config", "type": "java.util.List", "description": "a set of extended configurations ." + }, + { + "name": "spring.cloud.nacos.config.enabled", + "type": "java.lang.Boolean", + "defaultValue": true, + "description": "enable nacos config or not." } ] } \ No newline at end of file