1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

sync & commit in edgware

This commit is contained in:
fangjian0423
2019-11-11 14:22:01 +08:00
parent 2325455aa1
commit caa27b3f1c
27 changed files with 73 additions and 244 deletions

View File

@@ -44,11 +44,6 @@ public class NacosConfigAutoConfiguration {
return new NacosConfigProperties();
}
@Bean
public NacosConfigManager nacosConfigManager() {
return new NacosConfigManager();
}
@Bean
public NacosRefreshProperties nacosRefreshProperties() {
return new NacosRefreshProperties();
@@ -61,10 +56,10 @@ public class NacosConfigAutoConfiguration {
@Bean
public NacosContextRefresher nacosContextRefresher(
NacosConfigManager nacosConfigManager,
NacosConfigProperties configProperties,
NacosRefreshProperties nacosRefreshProperties,
NacosRefreshHistory refreshHistory) {
return new NacosContextRefresher(nacosRefreshProperties, refreshHistory,
nacosConfigManager.getConfigService());
configProperties.configServiceInstance());
}
}

View File

@@ -36,17 +36,10 @@ public class NacosConfigBootstrapConfiguration {
return new NacosConfigProperties();
}
@Bean
@ConditionalOnMissingBean
public NacosConfigManager nacosConfigManager() {
return new NacosConfigManager();
}
@Bean
public NacosPropertySourceLocator nacosPropertySourceLocator(
NacosConfigManager nacosConfigManager,
NacosConfigProperties nacosConfigProperties) {
return new NacosPropertySourceLocator(nacosConfigManager, nacosConfigProperties);
return new NacosPropertySourceLocator(nacosConfigProperties);
}
}

View File

@@ -1,51 +0,0 @@
/*
* Copyright (C) 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.cloud.nacos;
import com.alibaba.cloud.nacos.diagnostics.analyzer.NacosConnectionFailureException;
import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;
import org.springframework.beans.factory.annotation.Autowired;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
*/
public class NacosConfigManager {
private static ConfigService service = null;
@Autowired
private NacosConfigProperties properties;
public ConfigService getConfigService() {
if (service == null) {
try {
service = NacosFactory
.createConfigService(properties.getConfigServiceProperties());
properties.initConfigService(service);
}
catch (NacosException e) {
throw new NacosConnectionFailureException(properties.getServerAddr(),
e.getMessage(), e);
}
}
return service;
}
}

View File

@@ -22,7 +22,10 @@ import java.util.Properties;
import javax.annotation.PostConstruct;
import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -190,7 +193,7 @@ public class NacosConfigProperties {
*/
private List<Config> extConfig;
private ConfigService configService;
private static ConfigService configService;
// todo sts support
@@ -355,18 +358,22 @@ public class NacosConfigProperties {
}
/**
* @see NacosConfigManager#getConfigService() .
* @return ConfigService
*/
@Deprecated
public ConfigService configServiceInstance() {
if (null == configService) {
try {
configService = NacosFactory
.createConfigService(getConfigServiceProperties());
}
catch (NacosException e) {
log.error("create naming service error!properties={},e=,", this, e);
return null;
}
}
return configService;
}
public void initConfigService(ConfigService configService) {
this.configService = configService;
}
public Properties getConfigServiceProperties() {
Properties properties = new Properties();
properties.put(SERVER_ADDR, Objects.toString(this.serverAddr, ""));

View File

@@ -18,7 +18,6 @@ package com.alibaba.cloud.nacos.client;
import java.util.List;
import com.alibaba.cloud.nacos.NacosConfigManager;
import com.alibaba.cloud.nacos.NacosConfigProperties;
import com.alibaba.cloud.nacos.NacosPropertySourceRepository;
import com.alibaba.cloud.nacos.parser.NacosDataParserHandler;
@@ -58,18 +57,14 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
private NacosConfigProperties nacosConfigProperties;
private NacosConfigManager nacosConfigManager;
public NacosPropertySourceLocator(NacosConfigManager nacosConfigManager,
NacosConfigProperties nacosConfigProperties) {
this.nacosConfigManager = nacosConfigManager;
public NacosPropertySourceLocator(NacosConfigProperties nacosConfigProperties) {
this.nacosConfigProperties = nacosConfigProperties;
}
@Override
public PropertySource<?> locate(Environment env) {
ConfigService configService = nacosConfigManager.getConfigService();
ConfigService configService = nacosConfigProperties.configServiceInstance();
if (null == configService) {
log.warn("no instance of config service found, can't load config from nacos");

View File

@@ -16,7 +16,6 @@
package com.alibaba.cloud.nacos.endpoint;
import com.alibaba.cloud.nacos.NacosConfigManager;
import com.alibaba.cloud.nacos.NacosConfigProperties;
import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory;
@@ -38,9 +37,6 @@ public class NacosConfigEndpointAutoConfiguration {
@Autowired
private NacosConfigProperties nacosConfigProperties;
@Autowired
private NacosConfigManager nacosConfigManager;
@Autowired
private NacosRefreshHistory nacosRefreshHistory;
@@ -52,6 +48,7 @@ public class NacosConfigEndpointAutoConfiguration {
@Bean
public NacosConfigHealthIndicator nacosConfigHealthIndicator() {
return new NacosConfigHealthIndicator(nacosConfigManager.getConfigService());
return new NacosConfigHealthIndicator(
nacosConfigProperties.configServiceInstance());
}
}

View File

@@ -21,7 +21,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import com.alibaba.nacos.client.utils.StringUtils;
import org.springframework.util.StringUtils;
/**
* @author zkz
@@ -118,7 +118,7 @@ public abstract class AbstractNacosDataParser {
Properties properties = new Properties();
for (Map.Entry<String, String> entry : map.entrySet()) {
String key = entry.getKey();
if (StringUtils.isBlank(key)) {
if (StringUtils.isEmpty(key)) {
continue;
}
key = key.startsWith(DOT) ? key.replaceFirst("\\.", "") : key;

View File

@@ -22,10 +22,11 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import com.alibaba.nacos.client.utils.StringUtils;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.util.StringUtils;
/**
* @author zkz
*/

View File

@@ -25,14 +25,14 @@ import java.util.Properties;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import com.alibaba.nacos.client.utils.StringUtils;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.springframework.util.StringUtils;
/**
* With relatively few usage scenarios, only simple parsing is performed to reduce jar
* dependencies.