Search in sources :

Example 21 with ConfigurableEnvironment

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;
}
Also used : PropertySourcesConfig(org.grails.config.PropertySourcesConfig) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) MutablePropertySources(org.springframework.core.env.MutablePropertySources)

Example 22 with ConfigurableEnvironment

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"));
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) BitsquareEnvironment(io.bitsquare.app.BitsquareEnvironment) MutablePropertySources(org.springframework.core.env.MutablePropertySources) MockPropertySource(org.springframework.mock.env.MockPropertySource) PropertySource(org.springframework.core.env.PropertySource) MockPropertySource(org.springframework.mock.env.MockPropertySource) Test(org.junit.Test)

Example 23 with ConfigurableEnvironment

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;
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) CompositePropertySource(org.springframework.core.env.CompositePropertySource)

Example 24 with ConfigurableEnvironment

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;
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) ConfigurableWebEnvironment(org.springframework.web.context.ConfigurableWebEnvironment)

Example 25 with ConfigurableEnvironment

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));
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) MutablePropertySources(org.springframework.core.env.MutablePropertySources) Test(org.junit.Test)

Aggregations

ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)54 Test (org.junit.Test)27 StandardEnvironment (org.springframework.core.env.StandardEnvironment)18 MutablePropertySources (org.springframework.core.env.MutablePropertySources)10 SpringApplication (org.springframework.boot.SpringApplication)7 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)6 MockEnvironment (org.springframework.mock.env.MockEnvironment)6 CompositePropertySource (org.springframework.core.env.CompositePropertySource)4 MapPropertySource (org.springframework.core.env.MapPropertySource)4 Environment (org.springframework.core.env.Environment)3 ProfileAnnotatedComponent (example.profilescan.ProfileAnnotatedComponent)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintStream (java.io.PrintStream)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 AnnotatedGenericBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition)2 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)2 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)2 CommandLinePropertySource (org.springframework.core.env.CommandLinePropertySource)2 PropertySource (org.springframework.core.env.PropertySource)2