Example usage for org.springframework.core.env PropertySourcesPropertyResolver PropertySourcesPropertyResolver

List of usage examples for org.springframework.core.env PropertySourcesPropertyResolver PropertySourcesPropertyResolver

Introduction

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

Prototype

public PropertySourcesPropertyResolver(@Nullable PropertySources propertySources) 

Source Link

Document

Create a new resolver against the given property sources.

Usage

From source file:com.cloudera.director.aws.common.PropertyResolvers.java

/**
 * Creates a new property resolver with no properties.
 *
 * @return new property resolver//w  w  w  .ja v a  2  s.com
 */
public static PropertyResolver newEmptyPropertyResolver() {
    return new PropertySourcesPropertyResolver(new MutablePropertySources());
}

From source file:com.cloudera.director.aws.common.PropertyResolvers.java

/**
 * Creates a new property resolver that gets properties from the given map.
 *
 * @param m property map// ww w  .  jav a  2s  . c  o m
 * @return new property resolver
 * @throws NullPointerException if the map is null
 */
public static PropertyResolver newMapPropertyResolver(Map<String, String> m) {
    checkNotNull(m, "map is null");
    MutablePropertySources sources = new MutablePropertySources();
    sources.addFirst(new MapPropertySource("map", ImmutableMap.<String, Object>copyOf(m)));
    return new PropertySourcesPropertyResolver(sources);
}

From source file:com.dangdang.ddframe.reg.spring.placeholder.PlaceholderResolved.java

/**
 * ?????./*from  w w  w. j a va  2s.com*/
 * 
 * @param text ???
 * @return ????
 */
public String getResolvePlaceholderText(final String text) {
    if (placeholderMap.isEmpty()) {
        return text;
    }
    IllegalArgumentException missingException = null;
    for (Entry<String, PropertySourcesPlaceholderConfigurer> entry : placeholderMap.entrySet()) {
        PropertySourcesPropertyResolver propertyResolver;
        try {
            propertyResolver = new PropertySourcesPropertyResolver(
                    entry.getValue().getAppliedPropertySources());
        } catch (final IllegalStateException ex) {
            continue;
        } catch (final NoSuchMethodError ex) {
            try {
                propertyResolver = getPropertyResolverBeforeSpring4(entry.getValue());
            } catch (final ReflectiveOperationException e) {
                log.warn("Cannot get placeholder resolver.");
                return text;
            }
        }
        try {
            return propertyResolver.resolveRequiredPlaceholders(text);
        } catch (final IllegalArgumentException ex) {
            missingException = ex;
        }
    }
    if (null == missingException) {
        return text;
    }
    throw missingException;
}

From source file:com.dangdang.ddframe.reg.spring.placeholder.PlaceholderResolved.java

private PropertySourcesPropertyResolver getPropertyResolverBeforeSpring4(
        final PropertySourcesPlaceholderConfigurer placeholderConfigurer) throws ReflectiveOperationException {
    return new PropertySourcesPropertyResolver((PropertySources) PropertySourcesPlaceholderConfigurer.class
            .getField("propertySources").get(placeholderConfigurer));
}

From source file:com.cloudera.director.aws.common.PropertyResolvers.java

/**
 * Creates a property resolver that pulls from multiple property resource
 * locations. The first "built-in" location must be successfully loaded, but
 * all other "custom" locations must load only if {code}allowMissing{code} is
 * false./*from w  w  w .  j  a v  a2  s . c  o m*/
 *
 * @param allowMissing            true to allow custom resource locations to fail to load
 * @param builtInResourceLocation lowest precedence, required resource
 *                                location for properties
 * @param customResourceLocations additional resource locations for
 *                                properties, in increasing order of precedence
 * @return new property resolver
 * @throws IOException          if the built-in resource location could not be loaded,
 *                              or if {code}allowMissing{code} is false and any custom resource location
 *                              fails to load
 * @throws NullPointerException if any resource location is null
 */
public static PropertyResolver newMultiResourcePropertyResolver(boolean allowMissing,
        String builtInResourceLocation, String... customResourceLocations) throws IOException {
    MutablePropertySources sources = new MutablePropertySources();
    checkNotNull(builtInResourceLocation, "builtInResourceLocation is null");
    sources.addLast(buildPropertySource(BUILT_IN_NAME, builtInResourceLocation, false));
    String lastname = BUILT_IN_NAME;
    int customCtr = 1;
    for (String loc : customResourceLocations) {
        checkNotNull(loc, "customResourceLocations[" + (customCtr - 1) + "] is null");
        String thisname = CUSTOM_NAME_PREFIX + customCtr++;
        PropertySource source = buildPropertySource(thisname, loc, allowMissing);
        if (source != null) {
            sources.addBefore(lastname, source);
            lastname = thisname;
        }
    }

    return new PropertySourcesPropertyResolver(sources);
}

From source file:com.careerly.common.support.ReloadablePropertySourcesPlaceholderConfigurer.java

private void reload() throws IOException {
    logger.info("properties changed, reloading..");

    // Properties?
    Properties properties = super.mergeProperties();
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addLast(new PropertiesPropertySource(LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME, properties));
    ConfigurablePropertyResolver propertyResolver = new PropertySourcesPropertyResolver(propertySources);
    // BeanFactory??removeEmbeddedValueResolver??Resolver?
    valueResolver.expire();/*from   ww  w .ja va 2  s  .c om*/
    valueResolver = new PropertyStringValueResolver(propertyResolver);
    beanFactory.addEmbeddedValueResolver(valueResolver);

    // ??
    for (String beanName : beanNames) {
        Object bean = beanFactory.getBean(beanName);
        autowiredAnnotationBeanPostProcessor.processInjection(bean);
    }
}

From source file:com.textocat.textokit.eval.matching.MatchingConfigurationInitializerTest.java

private PropertyResolver makePropertyResolver(Map<String, Object> properties) {
    MutablePropertySources propSources = new MutablePropertySources();
    propSources.addFirst(new MapPropertySource("default", properties));
    PropertyResolver result = new PropertySourcesPropertyResolver(propSources);
    return result;
}

From source file:org.springframework.boot.ResourceBanner.java

private PropertyResolver getVersionResolver(Class<?> sourceClass) {
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addLast(new MapPropertySource("version", getVersionsMap(sourceClass)));
    return new PropertySourcesPropertyResolver(propertySources);
}

From source file:org.springframework.boot.ResourceBanner.java

private PropertyResolver getAnsiResolver() {
    MutablePropertySources sources = new MutablePropertySources();
    sources.addFirst(new AnsiPropertySource("ansi", true));
    return new PropertySourcesPropertyResolver(sources);
}