Example usage for org.springframework.core.env ConfigurableEnvironment getProperty

List of usage examples for org.springframework.core.env ConfigurableEnvironment getProperty

Introduction

In this page you can find the example usage for org.springframework.core.env ConfigurableEnvironment getProperty.

Prototype

String getProperty(String key, String defaultValue);

Source Link

Document

Return the property value associated with the given key, or defaultValue if the key cannot be resolved.

Usage

From source file:io.fabric8.spring.cloud.kubernetes.config.ConfigMapPropertySourceLocator.java

@Override
public PropertySource<?> locate(Environment environment) {
    if (environment instanceof ConfigurableEnvironment) {
        ConfigurableEnvironment env = (ConfigurableEnvironment) environment;
        String appName = env.getProperty(Constants.SPRING_APPLICATION_NAME,
                Constants.FALLBACK_APPLICATION_NAME);
        String name = properties.getName() == null || properties.getName().isEmpty() ? appName
                : properties.getName();//from   ww w.ja  va  2s  . c  o m
        String namespace = properties.getNamespace();
        return new ConfigMapPropertySource(client, name, namespace);
    }
    return null;
}

From source file:org.osiam.OsiamHome.java

public void configure(ConfigurableEnvironment environment) {
    String rawOsiamHome = environment.getProperty("osiam.home", System.getenv("HOME") + "/.osiam");
    checkState(!Strings.isNullOrEmpty(rawOsiamHome), "'osiam.home' is not set");
    osiamHome = Paths.get(rawOsiamHome).toAbsolutePath();
    environment.getPropertySources().addFirst(new PropertySource<Path>("osiamHome", osiamHome) {
        @Override/*ww w.j av  a 2 s.  c o m*/
        public Object getProperty(String name) {
            return "osiam.home".equals(name) ? source.toString() : null;
        }
    });
}

From source file:cf.spring.config.YamlPropertyContextInitializer.java

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    try {/*from w w  w  .  j  a v a2  s .  c o m*/
        final ConfigurableEnvironment environment = applicationContext.getEnvironment();
        final Resource resource = applicationContext
                .getResource(environment.getProperty(locationProperty, locationDefault));
        final YamlDocument yamlDocument;
        LOGGER.info("Loading config from: {}", resource);
        yamlDocument = YamlDocument.load(resource);
        final MutablePropertySources propertySources = environment.getPropertySources();
        final PropertySource propertySource = new YamlPropertySource(name, yamlDocument);
        if (addFirst) {
            propertySources.addFirst(propertySource);
        } else {
            propertySources.addLast(propertySource);
        }

        applicationContext.getBeanFactory().registerSingleton(name, yamlDocument);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:devbury.threadscope.ThreadScopeConfiguration.java

@Bean
public CustomScopeConfigurer threadCustomScopeConfigurer(ThreadScopeManager threadScopeManager,
        ConfigurableEnvironment environment) {
    CustomScopeConfigurer customScopeConfigurer = new CustomScopeConfigurer();
    // ConfigurationProperties not configured yet.  Use ConfigurableEnvironment to get properties.
    String scopeName = environment.getProperty(SCOPE_NAME_PROPERTY, ThreadScopeProperties.DEFAULT_SCOPE_NAME);
    logger.info("Thread scope name set to {}", scopeName);
    customScopeConfigurer.addScope(scopeName, threadScopeManager);
    return customScopeConfigurer;
}