fix:fix wrong internal config file load order. (#572)

pull/576/head
Haotian Zhang 2 years ago committed by GitHub
parent edb9236e60
commit a093d768e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -27,3 +27,4 @@
- [fix:fix heartbeat interval different configuration from polaris-java SDK.](https://github.com/Tencent/spring-cloud-tencent/pull/560) - [fix:fix heartbeat interval different configuration from polaris-java SDK.](https://github.com/Tencent/spring-cloud-tencent/pull/560)
- [Optimize: optimize report call result for restTemplate.](https://github.com/Tencent/spring-cloud-tencent/pull/562) - [Optimize: optimize report call result for restTemplate.](https://github.com/Tencent/spring-cloud-tencent/pull/562)
- [feat:add spring-cloud-starter-tencent-all and quickstart examples.](https://github.com/Tencent/spring-cloud-tencent/pull/567) - [feat:add spring-cloud-starter-tencent-all and quickstart examples.](https://github.com/Tencent/spring-cloud-tencent/pull/567)
- [fix:fix wrong internal config file load order.](https://github.com/Tencent/spring-cloud-tencent/pull/572)

@ -18,6 +18,8 @@
package com.tencent.cloud.polaris.config.adapter; package com.tencent.cloud.polaris.config.adapter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -123,47 +125,50 @@ public class PolarisConfigFileLocator implements PropertySourceLocator {
// priority: application-${profile} > application > boostrap-${profile} > boostrap // priority: application-${profile} > application > boostrap-${profile} > boostrap
String[] activeProfiles = environment.getActiveProfiles(); String[] activeProfiles = environment.getActiveProfiles();
buildInternalConfigFiles(internalConfigFiles, namespace, serviceName, activeProfiles); String[] defaultProfiles = environment.getDefaultProfiles();
List<String> profileList = new ArrayList<>();
// Compatible with defaultProfiles configuration if (ArrayUtils.isNotEmpty(activeProfiles)) {
if (ArrayUtils.isEmpty(activeProfiles)) { profileList.addAll(Arrays.asList(activeProfiles));
String[] defaultProfiles = environment.getDefaultProfiles();
buildInternalConfigFiles(internalConfigFiles, namespace, serviceName, defaultProfiles);
} }
else if (ArrayUtils.isNotEmpty(defaultProfiles)) {
// build default config properties files . profileList.addAll(Arrays.asList(defaultProfiles));
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application.properties")); }
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application.yml")); // build application config files
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap.properties")); buildInternalApplicationConfigFiles(internalConfigFiles, namespace, serviceName, profileList);
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap.yml")); // build bootstrap config files
buildInternalBootstrapConfigFiles(internalConfigFiles, namespace, serviceName, profileList);
return internalConfigFiles; return internalConfigFiles;
} }
private void buildInternalConfigFiles(List<ConfigFileMetadata> internalConfigFiles, String namespace, String serviceName, String[] profiles) { private void buildInternalApplicationConfigFiles(
List<ConfigFileMetadata> internalConfigFiles, String namespace, String serviceName, List<String> profileList) {
if (profiles != null) { for (String profile : profileList) {
for (String profile : profiles) { if (!StringUtils.hasText(profile)) {
if (!StringUtils.hasText(profile)) { continue;
continue;
}
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application-" + profile + ".properties"));
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application-" + profile + ".yml"));
} }
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application-" + profile + ".properties"));
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application-" + profile + ".yml"));
}
// build default config properties files.
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application.properties"));
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application.yml"));
}
for (String profile : profiles) { private void buildInternalBootstrapConfigFiles(
if (!StringUtils.hasText(profile)) { List<ConfigFileMetadata> internalConfigFiles, String namespace, String serviceName, List<String> profileList) {
continue; for (String profile : profileList) {
} if (!StringUtils.hasText(profile)) {
continue;
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap-" + profile + ".properties"));
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap-" + profile + ".yml"));
} }
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap-" + profile + ".properties"));
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap-" + profile + ".yml"));
} }
// build default config properties files.
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap.properties"));
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap.yml"));
} }
private void initCustomPolarisConfigFiles(CompositePropertySource compositePropertySource, private void initCustomPolarisConfigFiles(CompositePropertySource compositePropertySource,
List<ConfigFileGroup> configFileGroups) { List<ConfigFileGroup> configFileGroups) {
String namespace = polarisContextProperties.getNamespace(); String namespace = polarisContextProperties.getNamespace();

Loading…
Cancel
Save