mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
nacos 1.1.3 config data not exist
This commit is contained in:
@@ -156,8 +156,13 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
|
||||
String fileExtension = properties.getFileExtension();
|
||||
String nacosGroup = properties.getGroup();
|
||||
|
||||
// load directly once by default
|
||||
loadNacosDataIfPresent(compositePropertySource, dataIdPrefix, nacosGroup,
|
||||
fileExtension, true);
|
||||
// load with suffix, which have a higher priority than the default
|
||||
loadNacosDataIfPresent(compositePropertySource,
|
||||
dataIdPrefix + DOT + fileExtension, nacosGroup, fileExtension, true);
|
||||
// Loaded with profile, which have a higher priority than the suffix
|
||||
for (String profile : environment.getActiveProfiles()) {
|
||||
String dataId = dataIdPrefix + SEP1 + profile + DOT + fileExtension;
|
||||
loadNacosDataIfPresent(compositePropertySource, dataId, nacosGroup,
|
||||
@@ -168,22 +173,35 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
|
||||
private void loadNacosDataIfPresent(final CompositePropertySource composite,
|
||||
final String dataId, final String group, String fileExtension,
|
||||
boolean isRefreshable) {
|
||||
if (NacosContextRefresher.getRefreshCount() != 0) {
|
||||
NacosPropertySource ps;
|
||||
if (!isRefreshable) {
|
||||
ps = NacosPropertySourceRepository.getNacosPropertySource(dataId);
|
||||
}
|
||||
else {
|
||||
ps = nacosPropertySourceBuilder.build(dataId, group, fileExtension, true);
|
||||
}
|
||||
NacosPropertySource propertySource = this.loadNacosPropertySource(dataId, group,
|
||||
fileExtension, isRefreshable);
|
||||
this.addFirstPropertySource(composite, propertySource, false);
|
||||
}
|
||||
|
||||
composite.addFirstPropertySource(ps);
|
||||
private NacosPropertySource loadNacosPropertySource(final String dataId,
|
||||
final String group, String fileExtension, boolean isRefreshable) {
|
||||
if (NacosContextRefresher.getRefreshCount() != 0) {
|
||||
if (!isRefreshable) {
|
||||
return NacosPropertySourceRepository.getNacosPropertySource(dataId);
|
||||
}
|
||||
}
|
||||
else {
|
||||
NacosPropertySource ps = nacosPropertySourceBuilder.build(dataId, group,
|
||||
fileExtension, isRefreshable);
|
||||
composite.addFirstPropertySource(ps);
|
||||
return nacosPropertySourceBuilder.build(dataId, group, fileExtension,
|
||||
isRefreshable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the nacos configuration to the first place and maybe ignore the empty
|
||||
* configuration
|
||||
*/
|
||||
private void addFirstPropertySource(final CompositePropertySource composite,
|
||||
NacosPropertySource nacosPropertySource, boolean ignoreEmpty) {
|
||||
if (null == nacosPropertySource || null == composite) {
|
||||
return;
|
||||
}
|
||||
if (ignoreEmpty && nacosPropertySource.getSource().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
composite.addFirstPropertySource(nacosPropertySource);
|
||||
}
|
||||
|
||||
private static void checkDataIdFileExtension(String[] dataIdArray) {
|
||||
|
Reference in New Issue
Block a user