Top Description Fields Constructors Methods
org.springframework.context.support

public Class PropertySourcesPlaceholderConfigurer

extends PlaceholderConfigurerSupport
implements EnvironmentAware
Class Inheritance
All Implemented Interfaces
org.springframework.context.EnvironmentAware, org.springframework.beans.factory.Aware
Imports
java.io.IOException, java.util.Properties, org.springframework.beans.BeansException, org.springframework.beans.factory.BeanInitializationException, org.springframework.beans.factory.config.ConfigurableListableBeanFactory, .PlaceholderConfigurerSupport, org.springframework.context.EnvironmentAware, org.springframework.core.env.ConfigurableEnvironment, .ConfigurablePropertyResolver, .Environment, .MutablePropertySources, .PropertiesPropertySource, .PropertyResolver, .PropertySource, .PropertySources, .PropertySourcesPropertyResolver, org.springframework.lang.Nullable, org.springframework.util.Assert, .StringValueResolver

Specialization of PlaceholderConfigurerSupport that resolves ${...} placeholders within bean definition property values and @Value annotations against the current Spring Environment and its set of PropertySources.

This class is designed as a general replacement for PropertyPlaceholderConfigurer. It is used by default to support the property-placeholder element in working against the spring-context-3.1 or higher XSD; whereas, spring-context versions <= 3.0 default to PropertyPlaceholderConfigurer to ensure backward compatibility. See the spring-context XSD documentation for complete details.

Any local properties (e.g. those added via setProperties, setLocations et al.) are added as a PropertySource. Search precedence of local properties is based on the value of the localOverride property, which is by default false meaning that local properties are to be searched last, after all environment property sources.

See org.springframework.core.env.ConfigurableEnvironment and related javadocs for details on manipulating environment property sources.

Authors
Chris Beams, Juergen Hoeller, Sam Brannen
Since
3.1
See Also
org.springframework.core.env.ConfigurableEnvironment, org.springframework.beans.factory.config.PlaceholderConfigurerSupport, org.springframework.beans.factory.config.PropertyPlaceholderConfigurer

Field Summary

Modifier and TypeField and Description
private PropertySources
private Environment
public static final String
ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME

environmentProperties is the name given to the PropertySource that wraps the environment supplied to this configurer.

public static final String
LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME

localProperties is the name given to the PropertySource for the set of merged properties supplied to this configurer.

private MutablePropertySources
Inherited from org.springframework.beans.factory.config.PlaceholderConfigurerSupport:
DEFAULT_PLACEHOLDER_PREFIXDEFAULT_PLACEHOLDER_SUFFIXDEFAULT_VALUE_SEPARATORignoreUnresolvablePlaceholdersnullValueplaceholderPrefixplaceholderSuffixtrimValuesvalueSeparator

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected ConfigurablePropertyResolver
createPropertyResolver(MutablePropertySources
the property sources to use
propertySources
)

Create a ConfigurablePropertyResolver for the specified property sources.

public PropertySources

Returns:

the property sources that were applied
getAppliedPropertySources
()

Return the property sources that were actually applied during post-processing.

public void
postProcessBeanFactory(ConfigurableListableBeanFactory
the bean factory used by the application context
beanFactory
)

Overrides org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory.

Implements org.springframework.beans.factory.config.BeanFactoryPostProcessor.postProcessBeanFactory.

Processing occurs by replacing ${...} placeholders in bean definitions by resolving each against this configurer's set of PropertySources, which includes:
protected void
processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, final ConfigurablePropertyResolver propertyResolver)

Visit each bean definition in the given bean factory and attempt to replace ${...} property placeholders with values from the given properties.

protected void
public void
setEnvironment(Environment environment)

Implements org.springframework.context.EnvironmentAware.setEnvironment.

PropertySources from the given Environment will be searched when replacing ${...} placeholders.
public void
setPropertySources(PropertySources propertySources)

Customize the set of PropertySources to be used by this configurer.

Inherited from org.springframework.beans.factory.config.PlaceholderConfigurerSupport:
doProcessPropertiessetBeanFactorysetBeanNamesetIgnoreUnresolvablePlaceholderssetNullValuesetPlaceholderPrefixsetPlaceholderSuffixsetTrimValuessetValueSeparator

Field Detail

appliedPropertySourcesback to summary
private PropertySources appliedPropertySources
Annotations
@Nullable
environmentback to summary
private Environment environment
Annotations
@Nullable
ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAMEback to summary
public static final String ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME

environmentProperties is the name given to the PropertySource that wraps the environment supplied to this configurer.

LOCAL_PROPERTIES_PROPERTY_SOURCE_NAMEback to summary
public static final String LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME

localProperties is the name given to the PropertySource for the set of merged properties supplied to this configurer.

propertySourcesback to summary
private MutablePropertySources propertySources
Annotations
@Nullable

Constructor Detail

PropertySourcesPlaceholderConfigurerback to summary
public PropertySourcesPlaceholderConfigurer()

Method Detail

createPropertyResolverback to summary
protected ConfigurablePropertyResolver createPropertyResolver(MutablePropertySources propertySources)

Create a ConfigurablePropertyResolver for the specified property sources.

Parameters
propertySources:MutablePropertySources

the property sources to use

Since
6.0.12
getAppliedPropertySourcesback to summary
public PropertySources getAppliedPropertySources() throws IllegalStateException

Return the property sources that were actually applied during post-processing.

Returns:PropertySources

the property sources that were applied

Exceptions
IllegalStateException:
if the property sources have not yet been applied
Since
4.0
postProcessBeanFactoryback to summary
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException

Overrides org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory.

Implements org.springframework.beans.factory.config.BeanFactoryPostProcessor.postProcessBeanFactory.

Processing occurs by replacing ${...} placeholders in bean definitions by resolving each against this configurer's set of PropertySources, which includes:

If setPropertySources 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.

Parameters
beanFactory:ConfigurableListableBeanFactory

Doc from org.springframework.beans.factory.config.BeanFactoryPostProcessor.postProcessBeanFactory.

the bean factory used by the application context

Annotations
@Override
Exceptions
BeansException:

Doc from org.springframework.beans.factory.config.BeanFactoryPostProcessor.postProcessBeanFactory.

in case of errors

processPropertiesback to summary
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, final 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.

processPropertiesback to summary
protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)

Implements abstract org.springframework.beans.factory.config.PropertyResourceConfigurer.processProperties.

Implemented for compatibility with org.springframework.beans.factory.config.PlaceholderConfigurerSupport.

Parameters
beanFactory:ConfigurableListableBeanFactory

Doc from org.springframework.beans.factory.config.PropertyResourceConfigurer.processProperties.

the BeanFactory used by the application context

props:Properties

Doc from org.springframework.beans.factory.config.PropertyResourceConfigurer.processProperties.

the Properties to apply

Annotations
@Override
@Deprecated
Exceptions
UnsupportedOperationException:
in this implementation
setEnvironmentback to summary
public void setEnvironment(Environment environment)

Implements org.springframework.context.EnvironmentAware.setEnvironment.

PropertySources from the given Environment will be searched when replacing ${...} placeholders.

Annotations
@Override
See Also
setPropertySources, postProcessBeanFactory
setPropertySourcesback to summary
public void setPropertySources(PropertySources propertySources)

Customize the set of PropertySources to be used by this configurer.

Setting this property indicates that environment property sources and local properties should be ignored.

See Also
postProcessBeanFactory