Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public class NacosConfigProperties {

private boolean enableRemoteSyncConfig = false;

private boolean remoteFirst = false;

@JSONField(serialize = false)
private List<Config> extConfig = new ArrayList<>();

Expand Down Expand Up @@ -213,6 +215,14 @@ public void setEnableRemoteSyncConfig(boolean enableRemoteSyncConfig) {
this.enableRemoteSyncConfig = enableRemoteSyncConfig;
}

public boolean isRemoteFirst() {
return remoteFirst;
}

public void setRemoteFirst(boolean remoteFirst) {
this.remoteFirst = remoteFirst;
}

public List<Config> getExtConfig() {
return extConfig;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Properties;
import java.util.function.Function;

Expand Down Expand Up @@ -68,8 +69,15 @@ public void loadConfig() {
globalProperties, config.getType());
sources.addAll(elements);
}
for (NacosPropertySource propertySource : sources) {
mutablePropertySources.addLast(propertySource);

if (nacosConfigProperties.isRemoteFirst()) {
for (ListIterator<NacosPropertySource> itr = sources.listIterator(sources.size()); itr.hasPrevious();) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

远程配置应当是和Application.properties同样地位的,但是这里直接暴力的addFirst我觉得不太好,希望还是保留spring原有的对于配置优先级的概念,不要暴力的addFirst,而是添加到某个配置之前,某个配置之后这样做

mutablePropertySources.addFirst(itr.previous());
}
} else {
for (NacosPropertySource propertySource : sources) {
mutablePropertySources.addLast(propertySource);
}
}
}

Expand Down