mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
fix(nacos): Repair the conflict
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.alibaba.cloud.nacos.client;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
@@ -25,11 +24,10 @@ import java.util.Properties;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.alibaba.cloud.nacos.NacosPropertySourceRepository;
|
||||
import com.alibaba.cloud.nacos.parser.NacosDataParserHandler;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
|
||||
@@ -84,24 +82,18 @@ public class NacosPropertySourceBuilder {
|
||||
try {
|
||||
data = configService.getConfig(dataId, group, timeout);
|
||||
if (StringUtils.isEmpty(data)) {
|
||||
log.warn(
|
||||
"Ignore the empty nacos configuration and get it based on dataId[{}] & group[{}]",
|
||||
dataId, group);
|
||||
return EMPTY_PROPERTIES;
|
||||
}
|
||||
log.info(String.format(
|
||||
"Loading nacos data, dataId: '%s', group: '%s', data: %s", dataId,
|
||||
group, data));
|
||||
|
||||
log.info(String.format("Loading nacos data, dataId: '%s', group: '%s'",
|
||||
dataId, group));
|
||||
|
||||
if ("properties".equalsIgnoreCase(fileExtension)) {
|
||||
Properties properties = new Properties();
|
||||
|
||||
properties.load(new StringReader(data));
|
||||
return properties;
|
||||
}
|
||||
else if ("yaml".equalsIgnoreCase(fileExtension)
|
||||
|| "yml".equalsIgnoreCase(fileExtension)) {
|
||||
YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
|
||||
yamlFactory.setResources(new ByteArrayResource(data.getBytes()));
|
||||
return yamlFactory.getObject();
|
||||
}
|
||||
Properties properties = NacosDataParserHandler.getInstance()
|
||||
.parseNacosData(data, fileExtension);
|
||||
return properties == null ? EMPTY_PROPERTIES : properties;
|
||||
}
|
||||
catch (NacosException e) {
|
||||
log.error("get data from Nacos error,dataId:{}, ", dataId, e);
|
||||
|
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.alibaba.cloud.nacos.client;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.cloud.nacos.NacosConfigManager;
|
||||
@@ -32,6 +31,7 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import com.alibaba.cloud.nacos.NacosConfigProperties;
|
||||
import com.alibaba.cloud.nacos.NacosPropertySourceRepository;
|
||||
import com.alibaba.cloud.nacos.parser.NacosDataParserHandler;
|
||||
import com.alibaba.cloud.nacos.refresh.NacosContextRefresher;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
|
||||
@@ -48,8 +48,6 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
|
||||
private static final String SEP1 = "-";
|
||||
private static final String DOT = ".";
|
||||
private static final String SHARED_CONFIG_SEPARATOR_CHAR = "[,]";
|
||||
private static final List<String> SUPPORT_FILE_EXTENSION = Arrays.asList("properties",
|
||||
"yaml", "yml");
|
||||
|
||||
private NacosPropertySourceBuilder nacosPropertySourceBuilder;
|
||||
|
||||
@@ -131,7 +129,7 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
|
||||
|
||||
for (NacosConfigProperties.Config config : extConfigs) {
|
||||
String dataId = config.getDataId();
|
||||
String fileExtension = dataId.substring(dataId.lastIndexOf(".") + 1);
|
||||
String fileExtension = dataId.substring(dataId.lastIndexOf(DOT) + 1);
|
||||
loadNacosDataIfPresent(compositePropertySource, dataId, config.getGroup(),
|
||||
fileExtension, config.isRefresh());
|
||||
}
|
||||
@@ -189,24 +187,11 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
|
||||
}
|
||||
|
||||
private static void checkDataIdFileExtension(String[] dataIdArray) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
for (String dataId : dataIdArray) {
|
||||
if (!canLoadFileExtension(dataId)) {
|
||||
stringBuilder.append(dataId).append(",");
|
||||
}
|
||||
if (dataIdArray == null || dataIdArray.length < 1) {
|
||||
throw new IllegalStateException("The dataId cannot be empty");
|
||||
}
|
||||
|
||||
if (stringBuilder.length() > 0) {
|
||||
String result = stringBuilder.substring(0, stringBuilder.length() - 1);
|
||||
throw new IllegalStateException(String.format(
|
||||
"[%s] must end file extension with properties|yaml|yml", result));
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean canLoadFileExtension(String dataId) {
|
||||
return SUPPORT_FILE_EXTENSION.stream().anyMatch(
|
||||
(fileExtension) -> StringUtils.endsWithIgnoreCase(dataId, fileExtension));
|
||||
// Just decide that the current dataId must have a suffix
|
||||
NacosDataParserHandler.getInstance().checkDataId(dataIdArray);
|
||||
}
|
||||
|
||||
private boolean checkDataIdIsRefreshable(String refreshDataIds, String sharedDataId) {
|
||||
|
Reference in New Issue
Block a user