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;
|
package org.springframework.cloud.alibaba.nacos;
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanFactoryUtils;
|
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.NacosContextRefresher;
|
||||||
import org.springframework.cloud.alibaba.nacos.refresh.NacosRefreshHistory;
|
import org.springframework.cloud.alibaba.nacos.refresh.NacosRefreshHistory;
|
||||||
import org.springframework.cloud.alibaba.nacos.refresh.NacosRefreshProperties;
|
import org.springframework.cloud.alibaba.nacos.refresh.NacosRefreshProperties;
|
||||||
@ -28,6 +29,7 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
* @author juven.xuxb
|
* @author juven.xuxb
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@ConditionalOnProperty(name = "spring.cloud.nacos.config.enabled", matchIfMissing = true)
|
||||||
public class NacosConfigAutoConfiguration {
|
public class NacosConfigAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
@ -26,6 +26,7 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
* @author xiaojing
|
* @author xiaojing
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@ConditionalOnProperty(name = "spring.cloud.nacos.config.enabled", matchIfMissing = true)
|
||||||
public class NacosConfigBootstrapConfiguration {
|
public class NacosConfigBootstrapConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ -35,7 +36,6 @@ public class NacosConfigBootstrapConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnProperty(name = "spring.cloud.nacos.config.enabled", matchIfMissing = true)
|
|
||||||
public NacosPropertySourceLocator nacosPropertySourceLocator(
|
public NacosPropertySourceLocator nacosPropertySourceLocator(
|
||||||
NacosConfigProperties nacosConfigProperties) {
|
NacosConfigProperties nacosConfigProperties) {
|
||||||
return new NacosPropertySourceLocator(nacosConfigProperties);
|
return new NacosPropertySourceLocator(nacosConfigProperties);
|
||||||
|
@ -55,11 +55,6 @@ public class NacosConfigProperties {
|
|||||||
private static final Logger log = LoggerFactory
|
private static final Logger log = LoggerFactory
|
||||||
.getLogger(NacosConfigProperties.class);
|
.getLogger(NacosConfigProperties.class);
|
||||||
|
|
||||||
/**
|
|
||||||
* whether to enable nacos config.
|
|
||||||
*/
|
|
||||||
private boolean enabled = true;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nacos config server address
|
* nacos config server address
|
||||||
*/
|
*/
|
||||||
@ -140,19 +135,8 @@ public class NacosConfigProperties {
|
|||||||
|
|
||||||
private ConfigService configService;
|
private ConfigService configService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private Environment environment;
|
|
||||||
|
|
||||||
// todo sts support
|
// todo sts support
|
||||||
|
|
||||||
public boolean isEnabled() {
|
|
||||||
return enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEnabled(boolean enabled) {
|
|
||||||
this.enabled = enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getServerAddr() {
|
public String getServerAddr() {
|
||||||
return serverAddr;
|
return serverAddr;
|
||||||
}
|
}
|
||||||
@ -322,16 +306,15 @@ public class NacosConfigProperties {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "NacosConfigProperties{" + "enabled=" + enabled + ", serverAddr='"
|
return "NacosConfigProperties{" + "serverAddr='" + serverAddr + '\''
|
||||||
+ serverAddr + '\'' + ", encode='" + encode + '\'' + ", group='" + group
|
+ ", encode='" + encode + '\'' + ", group='" + group + '\'' + ", prefix='"
|
||||||
+ '\'' + ", prefix='" + prefix + '\'' + ", fileExtension='"
|
+ prefix + '\'' + ", fileExtension='" + fileExtension + '\''
|
||||||
+ fileExtension + '\'' + ", timeout=" + timeout + ", endpoint='"
|
+ ", timeout=" + timeout + ", endpoint='" + endpoint + '\''
|
||||||
+ endpoint + '\'' + ", namespace='" + namespace + '\'' + ", accessKey='"
|
+ ", namespace='" + namespace + '\'' + ", accessKey='" + accessKey + '\''
|
||||||
+ accessKey + '\'' + ", secretKey='" + secretKey + '\''
|
+ ", secretKey='" + secretKey + '\'' + ", contextPath='" + contextPath
|
||||||
+ ", contextPath='" + contextPath + '\'' + ", clusterName='" + clusterName
|
+ '\'' + ", clusterName='" + clusterName + '\'' + ", name='" + name + '\''
|
||||||
+ '\'' + ", name='" + name + '\'' + ", sharedDataids='" + sharedDataids
|
+ ", sharedDataids='" + sharedDataids + '\'' + ", refreshableDataids='"
|
||||||
+ '\'' + ", refreshableDataids='" + refreshableDataids + '\''
|
+ refreshableDataids + '\'' + ", extConfig=" + extConfig + '}';
|
||||||
+ ", extConfig=" + extConfig + '}';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigService configServiceInstance() {
|
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.actuate.endpoint.annotation.Endpoint;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||||
import org.springframework.cloud.alibaba.nacos.NacosConfigProperties;
|
import org.springframework.cloud.alibaba.nacos.NacosConfigProperties;
|
||||||
import org.springframework.cloud.alibaba.nacos.refresh.NacosRefreshHistory;
|
import org.springframework.cloud.alibaba.nacos.refresh.NacosRefreshHistory;
|
||||||
@ -31,6 +32,7 @@ import org.springframework.context.annotation.Bean;
|
|||||||
*/
|
*/
|
||||||
@ConditionalOnWebApplication
|
@ConditionalOnWebApplication
|
||||||
@ConditionalOnClass(value = Endpoint.class)
|
@ConditionalOnClass(value = Endpoint.class)
|
||||||
|
@ConditionalOnProperty(name = "spring.cloud.nacos.config.enabled", matchIfMissing = true)
|
||||||
public class NacosConfigEndpointAutoConfiguration {
|
public class NacosConfigEndpointAutoConfiguration {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -32,6 +32,12 @@
|
|||||||
"name": "spring.cloud.nacos.config.ext-config",
|
"name": "spring.cloud.nacos.config.ext-config",
|
||||||
"type": "java.util.List",
|
"type": "java.util.List",
|
||||||
"description": "a set of extended configurations ."
|
"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.AutoConfigureBefore;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.cloud.alibaba.nacos.ConditionalOnNacosDiscoveryEnabled;
|
import org.springframework.cloud.alibaba.nacos.ConditionalOnNacosDiscoveryEnabled;
|
||||||
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties;
|
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties;
|
||||||
@ -33,6 +34,7 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnNacosDiscoveryEnabled
|
@ConditionalOnNacosDiscoveryEnabled
|
||||||
@EnableConfigurationProperties
|
@EnableConfigurationProperties
|
||||||
|
@ConditionalOnProperty(value = "spring.cloud.nacos.discovery.enabled", matchIfMissing = true)
|
||||||
@AutoConfigureBefore({ SimpleDiscoveryClientAutoConfiguration.class,
|
@AutoConfigureBefore({ SimpleDiscoveryClientAutoConfiguration.class,
|
||||||
CommonsClientAutoConfiguration.class })
|
CommonsClientAutoConfiguration.class })
|
||||||
public class NacosDiscoveryClientAutoConfiguration {
|
public class NacosDiscoveryClientAutoConfiguration {
|
||||||
|
@ -5,6 +5,12 @@
|
|||||||
"defaultValue": "${spring.application.name}",
|
"defaultValue": "${spring.application.name}",
|
||||||
"description": "the service name to register, default value is ${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",
|
"name": "spring.cloud.nacos.discovery.namingLoadCacheAtStart",
|
||||||
"type": "java.lang.Boolean",
|
"type": "java.lang.Boolean",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user