Adds ignore imports and profiles to ConfigData.
This allows config server to apply profiles and imports while ignoring them on the client side. Fixes gh-1788
This commit is contained in:
@@ -27,6 +27,7 @@ import java.util.Map;
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import org.springframework.boot.context.config.ConfigData;
|
||||
import org.springframework.boot.context.config.ConfigData.Option;
|
||||
import org.springframework.boot.context.config.ConfigDataLoader;
|
||||
import org.springframework.boot.context.config.ConfigDataLoaderContext;
|
||||
import org.springframework.boot.context.properties.bind.Binder;
|
||||
@@ -125,7 +126,17 @@ public class ConfigServerConfigDataLoader implements ConfigDataLoader<ConfigServ
|
||||
// the existence of this property source confirms a successful
|
||||
// response from config server
|
||||
composite.add(0, new MapPropertySource("configClient", map));
|
||||
return new ConfigData(composite);
|
||||
try {
|
||||
return new ConfigData(composite, Option.IGNORE_IMPORTS, Option.IGNORE_PROFILES);
|
||||
}
|
||||
catch (NoSuchFieldError e) {
|
||||
// IGNORE_PROFILES was added in boot 2.4.3, for backwards
|
||||
// compatibility
|
||||
// IGNORE_IMPORTS alone causes NPE prior to 2.4.3
|
||||
// this will still throw an error if spring.profiles.include in
|
||||
// remote config
|
||||
return new ConfigData(composite);
|
||||
}
|
||||
}
|
||||
}
|
||||
errorBody = String.format("None of labels %s found", Arrays.toString(labels));
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.context.config.ConfigData;
|
||||
import org.springframework.boot.context.config.ConfigData.Option;
|
||||
import org.springframework.boot.context.properties.bind.BindContext;
|
||||
import org.springframework.boot.context.properties.bind.BindHandler;
|
||||
import org.springframework.boot.context.properties.bind.Bindable;
|
||||
@@ -100,7 +101,9 @@ public class ConfigServerConfigDataCustomizationIntegrationTests {
|
||||
public ConfigData apply(ConfigServerBootstrapper.LoadContext context) {
|
||||
applied = true;
|
||||
hasBinder = context.getBinder() != null;
|
||||
return context.getInvocation().apply(context.getLoaderContext(), context.getResource());
|
||||
ConfigData configData = context.getInvocation().apply(context.getLoaderContext(), context.getResource());
|
||||
assertThat(configData.getOptions()).contains(Option.IGNORE_IMPORTS, Option.IGNORE_PROFILES);
|
||||
return configData;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user