Example usage for org.springframework.context.support PropertySourcesPlaceholderConfigurer LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME

List of usage examples for org.springframework.context.support PropertySourcesPlaceholderConfigurer LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME

Introduction

In this page you can find the example usage for org.springframework.context.support PropertySourcesPlaceholderConfigurer LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME.

Prototype

String LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME

To view the source code for org.springframework.context.support PropertySourcesPlaceholderConfigurer LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME.

Click Source Link

Document

is the name given to the PropertySource for the set of #mergeProperties() merged properties supplied to this configurer.

Usage

From source file:org.carewebframework.api.spring.SpringUtil.java

/**
 * Returns a property value from the application context.
 * //from  w  w w .  j  a v a  2  s .c  o  m
 * @param name Property name.
 * @return Property value, or null if not found.
 */
public static String getProperty(String name) {
    ApplicationContext appContext = getRootAppContext();

    if (appContext == null) {
        return null;
    }

    String value = appContext.getEnvironment().getProperty(name);

    if (value == null) {
        PropertySourcesPlaceholderConfigurer cfg = appContext
                .getBean(PropertySourcesPlaceholderConfigurer.class);
        PropertySource<?> ps = cfg.getAppliedPropertySources()
                .get(PropertySourcesPlaceholderConfigurer.LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME);
        value = ps == null ? null : (String) ps.getProperty(name);
    }

    return value;
}

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

@Override
public void afterPropertiesSet() throws Exception {

    PropertySourcesPlaceholderConfigurer configurer = null;
    PropertySources propertySources = null;
    try {//from w  ww .java2  s  . c om
        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);
    }
}