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);
}
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");
}
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);
}
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);
}
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);
}
Aggregations