Search in sources :

Example 6 with PropertySourcesPropertyResolver

use of org.springframework.core.env.PropertySourcesPropertyResolver in project spring-boot by spring-projects.

the class ResourceBanner method getTitleResolver.

private PropertyResolver getTitleResolver(Class<?> sourceClass) {
    MutablePropertySources sources = new MutablePropertySources();
    String applicationTitle = getApplicationTitle(sourceClass);
    Map<String, Object> titleMap = Collections.<String, Object>singletonMap("application.title", (applicationTitle == null ? "" : applicationTitle));
    sources.addFirst(new MapPropertySource("title", titleMap));
    return new PropertySourcesPropertyResolver(sources);
}
Also used : PropertySourcesPropertyResolver(org.springframework.core.env.PropertySourcesPropertyResolver) MapPropertySource(org.springframework.core.env.MapPropertySource) MutablePropertySources(org.springframework.core.env.MutablePropertySources)

Example 7 with PropertySourcesPropertyResolver

use of org.springframework.core.env.PropertySourcesPropertyResolver in project spring-boot by spring-projects.

the class ResourceBanner method getVersionResolver.

private PropertyResolver getVersionResolver(Class<?> sourceClass) {
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addLast(new MapPropertySource("version", getVersionsMap(sourceClass)));
    return new PropertySourcesPropertyResolver(propertySources);
}
Also used : PropertySourcesPropertyResolver(org.springframework.core.env.PropertySourcesPropertyResolver) MapPropertySource(org.springframework.core.env.MapPropertySource) MutablePropertySources(org.springframework.core.env.MutablePropertySources)

Example 8 with PropertySourcesPropertyResolver

use of org.springframework.core.env.PropertySourcesPropertyResolver in project spring-boot by spring-projects.

the class LogFileTests method getPropertyResolver.

private PropertyResolver getPropertyResolver(String file, String path) {
    Map<String, Object> properties = new LinkedHashMap<>();
    properties.put("logging.file", file);
    properties.put("logging.path", path);
    PropertySource<?> propertySource = new MapPropertySource("properties", properties);
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addFirst(propertySource);
    return new PropertySourcesPropertyResolver(propertySources);
}
Also used : PropertySourcesPropertyResolver(org.springframework.core.env.PropertySourcesPropertyResolver) MapPropertySource(org.springframework.core.env.MapPropertySource) MutablePropertySources(org.springframework.core.env.MutablePropertySources) LinkedHashMap(java.util.LinkedHashMap)

Example 9 with PropertySourcesPropertyResolver

use of org.springframework.core.env.PropertySourcesPropertyResolver in project spring-framework by spring-projects.

the class PropertySourcesPlaceholderConfigurer method postProcessBeanFactory.

/**
	 * {@inheritDoc}
	 * <p>Processing occurs by replacing ${...} placeholders in bean definitions by resolving each
	 * against this configurer's set of {@link PropertySources}, which includes:
	 * <ul>
	 * <li>all {@linkplain org.springframework.core.env.ConfigurableEnvironment#getPropertySources
	 * environment property sources}, if an {@code Environment} {@linkplain #setEnvironment is present}
	 * <li>{@linkplain #mergeProperties merged local properties}, if {@linkplain #setLocation any}
	 * {@linkplain #setLocations have} {@linkplain #setProperties been}
	 * {@linkplain #setPropertiesArray specified}
	 * <li>any property sources set by calling {@link #setPropertySources}
	 * </ul>
	 * <p>If {@link #setPropertySources} is called, <strong>environment and local properties will be
	 * ignored</strong>. This method is designed to give the user fine-grained control over property
	 * sources, and once set, the configurer makes no assumptions about adding additional sources.
	 */
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    if (this.propertySources == null) {
        this.propertySources = new MutablePropertySources();
        if (this.environment != null) {
            this.propertySources.addLast(new PropertySource<Environment>(ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME, this.environment) {

                @Override
                public String getProperty(String key) {
                    return this.source.getProperty(key);
                }
            });
        }
        try {
            PropertySource<?> localPropertySource = new PropertiesPropertySource(LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME, mergeProperties());
            if (this.localOverride) {
                this.propertySources.addFirst(localPropertySource);
            } else {
                this.propertySources.addLast(localPropertySource);
            }
        } catch (IOException ex) {
            throw new BeanInitializationException("Could not load properties", ex);
        }
    }
    processProperties(beanFactory, new PropertySourcesPropertyResolver(this.propertySources));
    this.appliedPropertySources = this.propertySources;
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) PropertySourcesPropertyResolver(org.springframework.core.env.PropertySourcesPropertyResolver) PropertiesPropertySource(org.springframework.core.env.PropertiesPropertySource) Environment(org.springframework.core.env.Environment) MutablePropertySources(org.springframework.core.env.MutablePropertySources) IOException(java.io.IOException)

Aggregations

PropertySourcesPropertyResolver (org.springframework.core.env.PropertySourcesPropertyResolver)9 MutablePropertySources (org.springframework.core.env.MutablePropertySources)8 MapPropertySource (org.springframework.core.env.MapPropertySource)3 IOException (java.io.IOException)2 BeanInitializationException (org.springframework.beans.factory.BeanInitializationException)2 RelaxedPropertyResolver (org.springframework.boot.bind.RelaxedPropertyResolver)2 PropertiesPropertySource (org.springframework.core.env.PropertiesPropertySource)2 PropertySources (org.springframework.core.env.PropertySources)2 LinkedHashMap (java.util.LinkedHashMap)1 AnsiPropertySource (org.springframework.boot.ansi.AnsiPropertySource)1 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)1 Environment (org.springframework.core.env.Environment)1 PropertyResolver (org.springframework.core.env.PropertyResolver)1