diff --git a/client/src/main/java/com/alibaba/nacos/client/env/SearchableProperties.java b/client/src/main/java/com/alibaba/nacos/client/env/SearchableProperties.java index 0227a31f993..5b426e2e496 100644 --- a/client/src/main/java/com/alibaba/nacos/client/env/SearchableProperties.java +++ b/client/src/main/java/com/alibaba/nacos/client/env/SearchableProperties.java @@ -68,6 +68,11 @@ private SearchableProperties(PropertiesPropertySource propertiesPropertySource) JVM_ARGS_PROPERTY_SOURCE, SYSTEM_ENV_PROPERTY_SOURCE, DEFAULT_SETTING_PROPERTY_SOURCE); } + private SearchableProperties(PropertiesPropertySource propertiesPropertySource, List propertySources) { + this.propertiesPropertySource = propertiesPropertySource; + this.propertySources = propertySources; + } + @Override public String getProperty(String key) { return getProperty(key, null); @@ -216,7 +221,19 @@ private List sortPropertySource(SourceType firstType, @Override public NacosClientProperties derive() { - return new SearchableProperties(new PropertiesPropertySource(this.propertiesPropertySource)); + List propertySources = new ArrayList<>(this.propertySources); + PropertiesPropertySource newPropertiesPropertySource = new PropertiesPropertySource(this.propertiesPropertySource); + int index = 0; + for (int i = 0; i < propertySources.size(); i++) { + final AbstractPropertySource abstractPropertySource = propertySources.get(i); + final SourceType type = abstractPropertySource.getType(); + if (SourceType.PROPERTIES.equals(type)) { + index = i; + } + } + propertySources.set(index, newPropertiesPropertySource); + + return new SearchableProperties(newPropertiesPropertySource, propertySources); } @Override