mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Merge pull request #416 from flystar32/master
support switch Nacos Discovery/Config enabled
This commit is contained in:
commit
f66587fb32
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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() {
|
||||
|
@ -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
|
||||
|
@ -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."
|
||||
}
|
||||
]
|
||||
}
|
@ -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 {
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user