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

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

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

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

@Override
public void afterPropertiesSet() throws Exception {

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