diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/NativeEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/NativeEnvironmentRepository.java index e859ccbb..90e7183d 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/NativeEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/NativeEnvironmentRepository.java @@ -18,16 +18,17 @@ package org.springframework.cloud.config.server; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.config.ConfigFileApplicationListener; +import org.springframework.boot.context.config.ConfigFileEnvironmentPostProcessor; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.env.EnvironmentPostProcessingApplicationListener; import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.environment.PropertySource; import org.springframework.context.ConfigurableApplicationContext; @@ -77,7 +78,7 @@ public class NativeEnvironmentRepository implements EnvironmentRepository { } public boolean isFailOnError() { - return failOnError; + return this.failOnError; } @Override @@ -96,7 +97,8 @@ public class NativeEnvironmentRepository implements EnvironmentRepository { // Explicitly set the listeners (to exclude logging listener which would change // log levels in the caller) builder.application().setListeners( - Collections.singletonList(new ConfigFileApplicationListener())); + Arrays.asList(new ConfigFileEnvironmentPostProcessor(), + new EnvironmentPostProcessingApplicationListener())); ConfigurableApplicationContext context = builder.run(args); environment.getPropertySources().remove("profiles"); try { @@ -123,21 +125,21 @@ public class NativeEnvironmentRepository implements EnvironmentRepository { value.getLabel()); for (PropertySource source : value.getPropertySources()) { String name = source.getName(); - if (environment.getPropertySources().contains(name)) { + if (this.environment.getPropertySources().contains(name)) { continue; } name = name.replace("applicationConfig: [", ""); name = name.replace("]", ""); - if (searchLocations != null) { + if (this.searchLocations != null) { boolean matches = false; String normal = name; if (normal.startsWith("file:")) { - normal = StringUtils.cleanPath(new File(normal.substring("file:".length())) - .getAbsolutePath()); + normal = StringUtils.cleanPath(new File(normal.substring("file:" + .length())).getAbsolutePath()); } for (String pattern : StringUtils - .commaDelimitedListToStringArray(getLocations(searchLocations, - result.getLabel()))) { + .commaDelimitedListToStringArray(getLocations( + this.searchLocations, result.getLabel()))) { if (!pattern.contains(":")) { pattern = "file:" + pattern; } @@ -176,9 +178,9 @@ public class NativeEnvironmentRepository implements EnvironmentRepository { } list.add("--spring.config.name=" + config); list.add("--spring.cloud.bootstrap.enabled=false"); - list.add("--encrypt.failOnError=" + failOnError); + list.add("--encrypt.failOnError=" + this.failOnError); String[] locations = this.searchLocations; - if (searchLocations == null) { + if (this.searchLocations == null) { locations = DEFAULT_LOCATIONS; } list.add("--spring.config.location=" + getLocations(locations, label)); @@ -199,7 +201,7 @@ public class NativeEnvironmentRepository implements EnvironmentRepository { } public String[] getSearchLocations() { - return searchLocations; + return this.searchLocations; } public void setSearchLocations(String... locations) {