Skip to content

Instantly share code, notes, and snippets.

@SlyDen
Created November 25, 2015 08:57
Show Gist options
  • Select an option

  • Save SlyDen/d7ac9486a088707e04ab to your computer and use it in GitHub Desktop.

Select an option

Save SlyDen/d7ac9486a088707e04ab to your computer and use it in GitHub Desktop.
Marcel Overdijk's example to override application.properties defaults ... should work in boot after 1.3.1 (bug in 1.3)
@Order(Ordered.LOWEST_PRECEDENCE)
public class MyFrameworkPropertyDefaultsPostProcessor implements EnvironmentPostProcessor {
private static final String DEFAULT_MY_FRAMEWORK_PROPERTIES = "defaultMyFrameworkProperties";
private static final String DEFAULT_MY_FRAMEWORK_PROPERTIES_LOCATION = "/config/myFramework-application.yml";
private YamlPropertySourceLoader propertySourceLoader = new YamlPropertySourceLoader();
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
Resource myFrameworkDefaults = new ClassPathResource(DEFAULT_MY_FRAMEWORK_PROPERTIES_LOCATION);
String[] profiles = environment.getActiveProfiles();
load(environment, myFrameworkDefaults, null);
if (profiles.length > 0) {
for (String profile : profiles) {
load(environment, myFrameworkDefaults, profile);
}
}
}
private void load(ConfigurableEnvironment environment, Resource resource, String profile) {
try {
PropertySource<?> propertySource = propertySourceLoader.load(DEFAULT_MY_FRAMEWORK_PROPERTIES, resource, profile);
if (propertySource != null) {
environment.getPropertySources().addLast(propertySource);
}
} catch (IOException e) {
// ignore
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment