Skip to content
Closed
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 @@ -83,7 +83,7 @@ public void initialize(ConfigurableApplicationContext applicationContext) {
}
if (!empty) {
MutablePropertySources propertySources = applicationContext.getEnvironment()
.getPropertySources();
.getPropertySources();
if (propertySources.contains(BOOTSTRAP_PROPERTY_SOURCE_NAME)) {
propertySources.remove(BOOTSTRAP_PROPERTY_SOURCE_NAME);
}
Expand All @@ -101,27 +101,27 @@ private void setLogLevels(ConfigurableEnvironment environment) {
.<String> emptySet()));
}

private void insertPropertySources(MutablePropertySources propertySources,
CompositePropertySource composite) {
private void insertPropertySources(MutablePropertySources propertySources, CompositePropertySource composite) {
MutablePropertySources incoming = new MutablePropertySources();
incoming.addFirst(composite);
PropertySourceBootstrapProperties remoteProperties = new PropertySourceBootstrapProperties();
new RelaxedDataBinder(remoteProperties, "spring.cloud.config")
.bind(new PropertySourcesPropertyValues(incoming));
if (!remoteProperties.isAllowOverride()
|| remoteProperties.isOverrideSystemProperties()) {
propertySources.addFirst(composite);
return;
}
if (propertySources
.contains(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)) {
propertySources.addAfter(
StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME,
composite);
}
else {
propertySources.addLast(composite);
}

if(remoteProperties.isAllowOverride()) {
if(remoteProperties.isOverrideNoProperties()) {
propertySources.addLast(composite);
return;
} else if (!remoteProperties.isOverrideSystemProperties() && propertySources
.contains(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)) {
propertySources.addAfter(
StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, composite);
return;
}
}

propertySources.addFirst(composite);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ public class PropertySourceBootstrapProperties {
*/
private boolean overrideSystemProperties = true;

/**
* Flag to indicate that the external properties shouldn't override any other specified
* property sources
* Default false.
*/
private boolean overrideNoProperties = false;

/**
* Flag to indicate that {@link #isSystemPropertiesOverride()
* systemPropertiesOverride} can be used. Set to false to prevent users from changing
* the default accidentally. Default true.
* systemPropertiesOverride} and {@link #isOverrideNoProperties() overrideNoProperties} can be used.
* Set to false to prevent users from changing the default accidentally. Default true.
*/
private boolean allowOverride = true;

Expand All @@ -25,6 +32,14 @@ public boolean isOverrideSystemProperties() {
public void setOverrideSystemProperties(boolean overrideSystemProperties) {
this.overrideSystemProperties = overrideSystemProperties;
}

public boolean isOverrideNoProperties() {
return overrideNoProperties;
}

public void setOverrideNoProperties(boolean overrideNoProperties) {
this.overrideNoProperties = overrideNoProperties;
}

public boolean isAllowOverride() {
return allowOverride;
Expand Down