Search in sources :

Example 1 with PropertySourcesPropertyResolver

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

the class SpringBootTestContextBootstrapper method getConfiguredWebApplicationType.

private WebApplicationType getConfiguredWebApplicationType(MergedContextConfiguration configuration) {
    PropertySources sources = convertToPropertySources(configuration.getPropertySourceProperties());
    RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(new PropertySourcesPropertyResolver(sources), "spring.main.");
    String property = resolver.getProperty("web-application-type");
    return (property != null ? WebApplicationType.valueOf(property.toUpperCase()) : null);
}
Also used : PropertySourcesPropertyResolver(org.springframework.core.env.PropertySourcesPropertyResolver) PropertySources(org.springframework.core.env.PropertySources) MutablePropertySources(org.springframework.core.env.MutablePropertySources) RelaxedPropertyResolver(org.springframework.boot.bind.RelaxedPropertyResolver)

Example 2 with PropertySourcesPropertyResolver

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

the class SpringBootContextLoader method hasCustomServerPort.

private boolean hasCustomServerPort(List<String> properties) {
    PropertySources sources = convertToPropertySources(properties);
    RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(new PropertySourcesPropertyResolver(sources), "server.");
    return resolver.containsProperty("port");
}
Also used : PropertySourcesPropertyResolver(org.springframework.core.env.PropertySourcesPropertyResolver) PropertySources(org.springframework.core.env.PropertySources) MutablePropertySources(org.springframework.core.env.MutablePropertySources) RelaxedPropertyResolver(org.springframework.boot.bind.RelaxedPropertyResolver)

Example 3 with PropertySourcesPropertyResolver

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

the class ResourceBanner method getAnsiResolver.

private PropertyResolver getAnsiResolver() {
    MutablePropertySources sources = new MutablePropertySources();
    sources.addFirst(new AnsiPropertySource("ansi", true));
    return new PropertySourcesPropertyResolver(sources);
}
Also used : PropertySourcesPropertyResolver(org.springframework.core.env.PropertySourcesPropertyResolver) MutablePropertySources(org.springframework.core.env.MutablePropertySources) AnsiPropertySource(org.springframework.boot.ansi.AnsiPropertySource)

Example 4 with PropertySourcesPropertyResolver

use of org.springframework.core.env.PropertySourcesPropertyResolver in project uPortal by Jasig.

the class PortalPropertySourcesPlaceholderConfigurer method postProcessBeanFactory.

/**
     * Override the postProcessing. The default PropertySourcesPlaceholderConfigurer does not inject
     * local properties into the Environment object. It builds a local list of properties files and
     * then uses a transient Resolver to resolve the @Value annotations. That means that you are
     * unable to get to "local" properties (eg. portal.properties) after bean post-processing has
     * completed unless you are going to re-parse those file. This is similar to what
     * PropertiesManager does, but it uses all the property files configured, not just
     * portal.properties.
     *
     * <p>If we upgrade to spring 4, there are better/more efficient solutions available. I'm not
     * aware of better solutions for spring 3.x.
     *
     * @param beanFactory the bean factory
     * @throws BeansException if an error occurs while loading properties or wiring up beans
     */
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    if (propertyResolver == null) {
        try {
            MutablePropertySources sources = new MutablePropertySources();
            PropertySource<?> localPropertySource = new PropertiesPropertySource(EXTENDED_PROPERTIES_SOURCE, mergeProperties());
            sources.addLast(localPropertySource);
            propertyResolver = new PropertySourcesPropertyResolver(sources);
        } catch (IOException e) {
            throw new BeanInitializationException("Could not load properties", e);
        }
    }
    super.postProcessBeanFactory(beanFactory);
}
Also used : PropertySourcesPropertyResolver(org.springframework.core.env.PropertySourcesPropertyResolver) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) PropertiesPropertySource(org.springframework.core.env.PropertiesPropertySource) MutablePropertySources(org.springframework.core.env.MutablePropertySources) IOException(java.io.IOException)

Example 5 with PropertySourcesPropertyResolver

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

the class RelaxedPropertyResolver method ignoringUnresolvableNestedPlaceholders.

/**
	 * Return a property resolver for the environment, preferring one that ignores
	 * unresolvable nested placeholders.
	 * @param environment the source environment
	 * @param prefix the prefix
	 * @return a property resolver for the environment
	 * @since 1.4.3
	 */
public static RelaxedPropertyResolver ignoringUnresolvableNestedPlaceholders(Environment environment, String prefix) {
    Assert.notNull(environment, "Environment must not be null");
    PropertyResolver resolver = environment;
    if (environment instanceof ConfigurableEnvironment) {
        resolver = new PropertySourcesPropertyResolver(((ConfigurableEnvironment) environment).getPropertySources());
        ((PropertySourcesPropertyResolver) resolver).setIgnoreUnresolvableNestedPlaceholders(true);
    }
    return new RelaxedPropertyResolver(resolver, prefix);
}
Also used : PropertySourcesPropertyResolver(org.springframework.core.env.PropertySourcesPropertyResolver) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) PropertyResolver(org.springframework.core.env.PropertyResolver) PropertySourcesPropertyResolver(org.springframework.core.env.PropertySourcesPropertyResolver)

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