Skip to content

Commit

Permalink
Adds ignore imports and profiles to ConfigData.
Browse files Browse the repository at this point in the history
This allows config server to apply profiles and imports while ignoring them on the client side.

Fixes gh-1788
  • Loading branch information
spencergibb committed Mar 10, 2021
1 parent 823d201 commit 587cc97
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Expand Up @@ -27,6 +27,7 @@
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;
Expand Down Expand Up @@ -125,7 +126,17 @@ public ConfigData doLoad(ConfigDataLoaderContext context, ConfigServerConfigData
// 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));
Expand Down
Expand Up @@ -26,6 +26,7 @@
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;
Expand Down Expand Up @@ -100,7 +101,9 @@ static class Interceptor implements LoaderInterceptor {
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;
}

}
Expand Down

0 comments on commit 587cc97

Please sign in to comment.