use of org.springframework.core.env.ConfigurableEnvironment in project grails-core by grails.
the class DefaultGrailsApplication method getConfig.
public Config getConfig() {
if (config == null) {
if (parentContext != null) {
org.springframework.core.env.Environment environment = parentContext.getEnvironment();
if (environment instanceof ConfigurableEnvironment) {
MutablePropertySources propertySources = ((ConfigurableEnvironment) environment).getPropertySources();
this.config = new PropertySourcesConfig(propertySources);
} else {
this.config = new PropertySourcesConfig();
}
} else {
this.config = new PropertySourcesConfig();
}
setConfig(this.config);
}
return config;
}
use of org.springframework.core.env.ConfigurableEnvironment in project bitsquare by bitsquare.
the class BitsquareEnvironmentTests method testPropertySourcePrecedence.
@Test
public void testPropertySourcePrecedence() {
PropertySource commandlineProps = new MockPropertySource(BITSQUARE_COMMANDLINE_PROPERTY_SOURCE_NAME).withProperty("key.x", "x.commandline");
PropertySource filesystemProps = new MockPropertySource(BITSQUARE_APP_DIR_PROPERTY_SOURCE_NAME).withProperty("key.x", "x.env").withProperty("key.y", "y.env");
ConfigurableEnvironment env = new BitsquareEnvironment(commandlineProps) {
@Override
PropertySource<?> appDirProperties() {
return filesystemProps;
}
};
MutablePropertySources propertySources = env.getPropertySources();
assertThat(propertySources.precedenceOf(named(BITSQUARE_COMMANDLINE_PROPERTY_SOURCE_NAME)), equalTo(0));
assertThat(propertySources.precedenceOf(named(SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)), equalTo(1));
assertThat(propertySources.precedenceOf(named(SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)), equalTo(2));
assertThat(propertySources.precedenceOf(named(BITSQUARE_APP_DIR_PROPERTY_SOURCE_NAME)), equalTo(3));
assertThat(propertySources.precedenceOf(named(BITSQUARE_HOME_DIR_PROPERTY_SOURCE_NAME)), equalTo(4));
assertThat(propertySources.precedenceOf(named(BITSQUARE_CLASSPATH_PROPERTY_SOURCE_NAME)), equalTo(5));
assertThat(propertySources.precedenceOf(named(BITSQUARE_DEFAULT_PROPERTY_SOURCE_NAME)), equalTo(6));
assertThat(propertySources.size(), equalTo(7));
// commandline value wins due to precedence
assertThat(env.getProperty("key.x"), equalTo("x.commandline"));
// env value wins because it's the only one available
assertThat(env.getProperty("key.y"), equalTo("y.env"));
}
use of org.springframework.core.env.ConfigurableEnvironment in project cas by apereo.
the class MongoDbPropertySourceLocator method locate.
@Override
public PropertySource<?> locate(final Environment environment) {
if (environment instanceof ConfigurableEnvironment) {
final String sourceName = MongoDbPropertySource.class.getSimpleName();
final CompositePropertySource composite = new CompositePropertySource(sourceName);
final MongoDbPropertySource source = new MongoDbPropertySource(sourceName, mongo);
composite.addFirstPropertySource(source);
return composite;
}
return null;
}
use of org.springframework.core.env.ConfigurableEnvironment in project grails-core by grails.
the class GrailsWebApplicationContext method getEnvironment.
@Override
public ConfigurableWebEnvironment getEnvironment() {
ConfigurableEnvironment env = super.getEnvironment();
Assert.isInstanceOf(ConfigurableWebEnvironment.class, env, "ConfigurableWebApplication environment must be of type ConfigurableWebEnvironment");
return (ConfigurableWebEnvironment) env;
}
use of org.springframework.core.env.ConfigurableEnvironment in project spring-framework by spring-projects.
the class StandardServletEnvironmentTests method propertySourceOrder.
@Test
public void propertySourceOrder() throws Exception {
SimpleNamingContextBuilder.emptyActivatedContextBuilder();
ConfigurableEnvironment env = new StandardServletEnvironment();
MutablePropertySources sources = env.getPropertySources();
assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)), equalTo(0));
assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)), equalTo(1));
assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME)), equalTo(2));
assertThat(sources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)), equalTo(3));
assertThat(sources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)), equalTo(4));
assertThat(sources.size(), is(5));
}
Aggregations