Moves bootstrap enabled property to refresh property source.
LegacyContextRefresher used to set `spring.cloud.bootstrap.enabled=true` as a property using the api of `SpringApplicationBuilder`. This change moves the setting of properties for refresh from ContextRefresher to LegacyContextRefresher since they are only applicable there. The bootstrap enabled propery is now set on the refresh property source rather than the api. Fixes gh-892
This commit is contained in:
@@ -70,7 +70,8 @@ public abstract class TextEncryptorUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Register all classes that need a {@link TextEncryptor} in {@link TextEncryptorConfigBootstrapper}.
|
||||
* Register all classes that need a {@link TextEncryptor} in
|
||||
* {@link TextEncryptorConfigBootstrapper}.
|
||||
* @param registry the BootstrapRegistry.
|
||||
*/
|
||||
public static void register(BootstrapRegistry registry) {
|
||||
@@ -156,8 +157,8 @@ public abstract class TextEncryptorUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to check if legacy bootstrap mode is enabled. This is either if the
|
||||
* boot legacy processing property is set or spring.cloud.bootstrap.enabled=true.
|
||||
* Method to check if legacy bootstrap mode is enabled. This is either if the boot
|
||||
* legacy processing property is set or spring.cloud.bootstrap.enabled=true.
|
||||
* @param environment where to check properties.
|
||||
* @return true if bootstrap enabled.
|
||||
*/
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.springframework.core.env.CommandLinePropertySource;
|
||||
import org.springframework.core.env.CompositePropertySource;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.EnumerablePropertySource;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.core.env.MutablePropertySources;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
@@ -131,12 +130,6 @@ public abstract class ContextRefresher {
|
||||
}
|
||||
environment.setActiveProfiles(input.getActiveProfiles());
|
||||
environment.setDefaultProfiles(input.getDefaultProfiles());
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("spring.jmx.enabled", false);
|
||||
map.put("spring.main.sources", "");
|
||||
// gh-678 without this apps with this property set to REACTIVE or SERVLET fail
|
||||
map.put("spring.main.web-application-type", "NONE");
|
||||
capturedPropertySources.addFirst(new MapPropertySource(REFRESH_ARGS_PROPERTY_SOURCE, map));
|
||||
return environment;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
package org.springframework.cloud.context.refresh;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.Banner;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
@@ -26,6 +28,7 @@ import org.springframework.cloud.bootstrap.BootstrapApplicationListener;
|
||||
import org.springframework.cloud.bootstrap.BootstrapConfigFileApplicationListener;
|
||||
import org.springframework.cloud.context.scope.refresh.RefreshScope;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.core.env.MutablePropertySources;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
@@ -57,8 +60,16 @@ public class LegacyContextRefresher extends ContextRefresher {
|
||||
ConfigurableApplicationContext capture = null;
|
||||
try {
|
||||
StandardEnvironment environment = copyEnvironment(getContext().getEnvironment());
|
||||
SpringApplicationBuilder builder = new SpringApplicationBuilder(Empty.class)
|
||||
.properties(BOOTSTRAP_ENABLED_PROPERTY + "=true").bannerMode(Banner.Mode.OFF)
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("spring.jmx.enabled", false);
|
||||
map.put("spring.main.sources", "");
|
||||
// gh-678 without this apps with this property set to REACTIVE or SERVLET fail
|
||||
map.put("spring.main.web-application-type", "NONE");
|
||||
map.put(BOOTSTRAP_ENABLED_PROPERTY, Boolean.TRUE.toString());
|
||||
environment.getPropertySources().addFirst(new MapPropertySource(REFRESH_ARGS_PROPERTY_SOURCE, map));
|
||||
|
||||
SpringApplicationBuilder builder = new SpringApplicationBuilder(Empty.class).bannerMode(Banner.Mode.OFF)
|
||||
.web(WebApplicationType.NONE).environment(environment);
|
||||
// Just the listeners that affect the environment (e.g. excluding logging
|
||||
// listener because it has side effects)
|
||||
|
||||
@@ -78,7 +78,6 @@ public class ContextRefresherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // FIXME: legacy
|
||||
public void bootstrapPropertySourceAlwaysFirst() {
|
||||
// Use spring.cloud.bootstrap.name to switch off the defaults (which would pick up
|
||||
// a bootstrapProperties immediately
|
||||
|
||||
Reference in New Issue
Block a user