List of usage examples for org.springframework.context.support PropertySourcesPlaceholderConfigurer getAppliedPropertySources
public PropertySources getAppliedPropertySources() throws IllegalStateException
From source file:org.carewebframework.api.spring.SpringUtil.java
/** * Returns a property value from the application context. * //from ww w. j ava2 s .c o m * @param name Property name. * @return Property value, or null if not found. */ public static String getProperty(String name) { ApplicationContext appContext = getRootAppContext(); if (appContext == null) { return null; } String value = appContext.getEnvironment().getProperty(name); if (value == null) { PropertySourcesPlaceholderConfigurer cfg = appContext .getBean(PropertySourcesPlaceholderConfigurer.class); PropertySource<?> ps = cfg.getAppliedPropertySources() .get(PropertySourcesPlaceholderConfigurer.LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME); value = ps == null ? null : (String) ps.getProperty(name); } return value; }
From source file:com.github.dactiv.fear.commons.Apis.java
@Override public void afterPropertiesSet() throws Exception { PropertySourcesPlaceholderConfigurer configurer = null; PropertySources propertySources = null; try {// w w w .j a va2s . c om 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); } }
From source file:org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.java
private PropertySources deducePropertySources() { PropertySourcesPlaceholderConfigurer configurer = getSinglePropertySourcesPlaceholderConfigurer(); if (configurer != null) { // Flatten the sources into a single list so they can be iterated return new FlatPropertySources(configurer.getAppliedPropertySources()); }/*from w ww . j a v a 2 s . c o m*/ if (this.environment instanceof ConfigurableEnvironment) { MutablePropertySources propertySources = ((ConfigurableEnvironment) this.environment) .getPropertySources(); return new FlatPropertySources(propertySources); } // empty, so not very useful, but fulfils the contract logger.warn( "Unable to obtain PropertySources from " + "PropertySourcesPlaceholderConfigurer or Environment"); return new MutablePropertySources(); }
From source file:org.springframework.boot.context.properties.PropertySourcesDeducer.java
public PropertySources getPropertySources() { PropertySourcesPlaceholderConfigurer configurer = getSinglePropertySourcesPlaceholderConfigurer(); if (configurer != null) { return configurer.getAppliedPropertySources(); }// ww w. j a v a2 s .c om MutablePropertySources sources = extractEnvironmentPropertySources(); if (sources != null) { return sources; } throw new IllegalStateException( "Unable to obtain PropertySources from " + "PropertySourcesPlaceholderConfigurer or Environment"); }