Example usage for org.springframework.core.env PropertySources get

List of usage examples for org.springframework.core.env PropertySources get

Introduction

In this page you can find the example usage for org.springframework.core.env PropertySources get.

Prototype

@Nullable
PropertySource<?> get(String name);

Source Link

Document

Return the property source with the given name, null if not found.

Usage

From source file:com.github.dactiv.fear.commons.Apis.java

@Override
public void afterPropertiesSet() throws Exception {

    PropertySourcesPlaceholderConfigurer configurer = null;
    PropertySources propertySources = null;
    try {//www. j a v a 2 s  . co m
        configurer = applicationContext.getBean(PropertySourcesPlaceholderConfigurer.class);
        propertySources = configurer.getAppliedPropertySources();
    } catch (Exception e) {
        LOGGER.warn("install " + PropertySourcesPlaceholderConfigurer.LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME
                + " error", e);
    }

    if (propertySources == null) {
        return;
    }

    Field field = ReflectionUtils.findField(configurer.getClass(), "environment");
    field.setAccessible(Boolean.TRUE);
    environment = (Environment) field.get(configurer);
    if (environment instanceof ConfigurableEnvironment) {
        ConfigurableEnvironment ce = (ConfigurableEnvironment) environment;
        MutablePropertySources sources = ce.getPropertySources();
        PropertySource<?> ps = propertySources
                .get(PropertySourcesPlaceholderConfigurer.LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME);
        sources.addFirst(ps);
    }
}