in spring-cloud-alibaba-starters/spring-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/client/NacosPropertySource.java [73:114]
private static Map<String, Object> getSourceMap(String group, String dataId,
List<PropertySource<?>> propertySources) {
if (CollectionUtils.isEmpty(propertySources)) {
return Collections.emptyMap();
}
// If only one, return the internal element, otherwise wrap it.
if (propertySources.size() == 1) {
PropertySource propertySource = propertySources.get(0);
if (propertySource != null && propertySource.getSource() instanceof Map source) {
return source;
}
}
Map<String, Object> sourceMap = new LinkedHashMap<>();
List<PropertySource<?>> otherTypePropertySources = new ArrayList<>();
for (PropertySource<?> propertySource : propertySources) {
if (propertySource == null) {
continue;
}
if (propertySource instanceof MapPropertySource mapPropertySource) {
// If the Nacos configuration file uses "---" to separate property name,
// propertySources will be multiple documents, and every document is a
// map.
// see org.springframework.boot.env.YamlPropertySourceLoader#load
Map<String, Object> source = mapPropertySource.getSource();
sourceMap.putAll(source);
}
else {
otherTypePropertySources.add(propertySource);
}
}
// Other property sources which is not instanceof MapPropertySource will be put as
// it is,
// and the internal elements cannot be directly retrieved,
// so the user needs to implement the retrieval logic by himself
if (!otherTypePropertySources.isEmpty()) {
sourceMap.put(String.join(NacosConfigProperties.COMMAS, dataId, group),
otherTypePropertySources);
}
return sourceMap;
}