Class PropertySourcesPlaceholderConfigurer
- java.lang.Object
- org.springframework.core.io.support.PropertiesLoaderSupport
- org.springframework.beans.factory.config.PropertyResourceConfigurer
- org.springframework.beans.factory.config.PlaceholderConfigurerSupport
- org.springframework.context.support.PropertySourcesPlaceholderConfigurer
- All Implemented Interfaces:
Aware
,BeanFactoryAware
,BeanNameAware
,BeanFactoryPostProcessor
,EnvironmentAware
,Ordered
,PriorityOrdered
public class PropertySourcesPlaceholderConfigurer extends PlaceholderConfigurerSupport implements EnvironmentAware
Specialization ofPlaceholderConfigurerSupport
that resolves ${...} placeholders within bean definition property values and@Value
annotations against the current SpringEnvironment
and its set ofPropertySources
.This class is designed as a general replacement for
PropertyPlaceholderConfigurer
introduced in Spring 3.1. It is used by default to support theproperty-placeholder
element in working against the spring-context-3.1 or higher XSD, whereas spring-context versions <= 3.0 default toPropertyPlaceholderConfigurer
to ensure backward compatibility. See the spring-context XSD documentation for complete details.Any local properties (e.g. those added via
PropertiesLoaderSupport.setProperties(java.util.Properties)
,PropertiesLoaderSupport.setLocations(org.springframework.core.io.Resource...)
et al.) are added as aPropertySource
. Search precedence of local properties is based on the value of thelocalOverride
property, which is by defaultfalse
meaning that local properties are to be searched last, after all environment property sources.See
ConfigurableEnvironment
and related javadocs for details on manipulating environment property sources.- Since:
- 3.1
- Author:
- Chris Beams, Juergen Hoeller
- See Also:
ConfigurableEnvironment
,PlaceholderConfigurerSupport
,PropertyPlaceholderConfigurer
Field Summary
Fields Modifier and Type Field Description static String
ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME
"environmentProperties" is the name given to thePropertySource
that wraps the environment supplied to this configurer.static String
LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME
"localProperties" is the name given to thePropertySource
for the set of merged properties supplied to this configurer.Fields inherited from class org.springframework.beans.factory.config.PlaceholderConfigurerSupport
DEFAULT_PLACEHOLDER_PREFIX, DEFAULT_PLACEHOLDER_SUFFIX, DEFAULT_VALUE_SEPARATOR, ignoreUnresolvablePlaceholders, nullValue, placeholderPrefix, placeholderSuffix, trimValues, valueSeparator
Fields inherited from class org.springframework.core.io.support.PropertiesLoaderSupport
localOverride, localProperties, logger
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor Summary
Constructors Constructor Description PropertySourcesPlaceholderConfigurer()
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description PropertySources
getAppliedPropertySources()
Return the property sources that were actually applied duringpost-processing
.void
postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
Processing occurs by replacing ${...} placeholders in bean definitions by resolving each against this configurer's set ofPropertySources
, which includes: all environment property sources, if anEnvironment
is presentmerged local properties, if anyhavebeenspecified any property sources set by callingsetPropertySources(org.springframework.core.env.PropertySources)
protected void
processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)
Deprecated.protected void
processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, ConfigurablePropertyResolver propertyResolver)
Visit each bean definition in the given bean factory and attempt to replace ${...} property placeholders with values from the given properties.void
setEnvironment(Environment environment)
PropertySources
from the givenEnvironment
will be searched when replacing ${...} placeholders.void
setPropertySources(PropertySources propertySources)
Customize the set ofPropertySources
to be used by this configurer.Methods inherited from class org.springframework.beans.factory.config.PlaceholderConfigurerSupport
doProcessProperties, setBeanFactory, setBeanName, setIgnoreUnresolvablePlaceholders, setNullValue, setPlaceholderPrefix, setPlaceholderSuffix, setTrimValues, setValueSeparator
Methods inherited from class org.springframework.beans.factory.config.PropertyResourceConfigurer
convertProperties, convertProperty, convertPropertyValue, getOrder, setOrder
Methods inherited from class org.springframework.core.io.support.PropertiesLoaderSupport
loadProperties, mergeProperties, setFileEncoding, setIgnoreResourceNotFound, setLocalOverride, setLocation, setLocations, setProperties, setPropertiesArray, setPropertiesPersister
Field Detail
LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME
public static final String LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME
"localProperties" is the name given to thePropertySource
for the set of merged properties supplied to this configurer.- See Also:
- Constant Field Values
ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME
public static final String ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME
"environmentProperties" is the name given to thePropertySource
that wraps the environment supplied to this configurer.- See Also:
- Constant Field Values
Constructor Detail
PropertySourcesPlaceholderConfigurer
public PropertySourcesPlaceholderConfigurer()
Method Detail
setPropertySources
public void setPropertySources(PropertySources propertySources)
Customize the set ofPropertySources
to be used by this configurer.Setting this property indicates that environment property sources and local properties should be ignored.
setEnvironment
public void setEnvironment(Environment environment)
PropertySources
from the givenEnvironment
will be searched when replacing ${...} placeholders.
postProcessBeanFactory
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException
Processing occurs by replacing ${...} placeholders in bean definitions by resolving each against this configurer's set ofPropertySources
, which includes:- all environment property sources, if an
Environment
is present - merged local properties, if anyhavebeenspecified
- any property sources set by calling
setPropertySources(org.springframework.core.env.PropertySources)
If
setPropertySources(org.springframework.core.env.PropertySources)
is called, environment and local properties will be ignored. 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.- Specified by:
postProcessBeanFactory
in interfaceBeanFactoryPostProcessor
- Overrides:
postProcessBeanFactory
in classPropertyResourceConfigurer
- Parameters:
beanFactory
- the bean factory used by the application context- Throws:
BeansException
- in case of errors
- all environment property sources, if an
processProperties
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, ConfigurablePropertyResolver propertyResolver) throws BeansException
Visit each bean definition in the given bean factory and attempt to replace ${...} property placeholders with values from the given properties.- Throws:
BeansException
processProperties
@Deprecated protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)
Deprecated.Implemented for compatibility withPlaceholderConfigurerSupport
.- Specified by:
processProperties
in classPropertyResourceConfigurer
- Parameters:
beanFactory
- the BeanFactory used by the application contextprops
- the Properties to apply- Throws:
UnsupportedOperationException
- in this implementation
getAppliedPropertySources
public PropertySources getAppliedPropertySources() throws IllegalStateException
Return the property sources that were actually applied duringpost-processing
.- Returns:
- the property sources that were applied
- Throws:
IllegalStateException
- if the property sources have not yet been applied- Since:
- 4.0