Top Description Fields Constructors Methods
org.springframework.beans.factory.config

public abstract Class PlaceholderConfigurerSupport

extends PropertyResourceConfigurer
implements BeanNameAware, BeanFactoryAware
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware
Known Direct Subclasses
org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
Imports
org.springframework.beans.factory.BeanDefinitionStoreException, .BeanFactory, .BeanFactoryAware, .BeanNameAware, org.springframework.lang.Nullable, org.springframework.util.StringValueResolver

Abstract base class for property resource configurers that resolve placeholders in bean definition property values. Implementations pull values from a properties file or other property source into bean definitions.

The default placeholder syntax follows the Ant / Log4J / JSP EL style:

${...}
Example XML bean definition:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  <property name="driverClassName" value="${driver}" />
  <property name="url" value="jdbc:${dbname}" />
</bean>
Example properties file:
driver=com.mysql.jdbc.Driver
dbname=mysql:mydb
Annotated bean definitions may take advantage of property replacement using the @Value annotation:
@Value("${person.age}")
Implementations check simple property values, lists, maps, props, and bean names in bean references. Furthermore, placeholder values can also cross-reference other placeholders, like:
rootPath=myrootdir
subPath=${rootPath}/subdir
In contrast to PropertyOverrideConfigurer, subclasses of this type allow filling in of explicit placeholders in bean definitions.

If a configurer cannot resolve a placeholder, a BeanDefinitionStoreException will be thrown. If you want to check against multiple properties files, specify multiple resources via the locations property. You can also define multiple configurers, each with its own placeholder syntax. Use ignoreUnresolvablePlaceholders to intentionally suppress throwing an exception if a placeholder cannot be resolved.

Default property values can be defined globally for each configurer instance via the properties property, or on a property-by-property basis using the value separator which is ":" by default and customizable via setValueSeparator(String).

Example XML property with default value:

  <property name="url" value="jdbc:${dbname:defaultdb}" />
Authors
Chris Beams, Juergen Hoeller
Since
3.1
See Also
PropertyPlaceholderConfigurer, org.springframework.context.support.PropertySourcesPlaceholderConfigurer

Field Summary

Modifier and TypeField and Description
private BeanFactory
private String
public static final String
DEFAULT_PLACEHOLDER_PREFIX

Default placeholder prefix: ${.

public static final String
DEFAULT_PLACEHOLDER_SUFFIX

Default placeholder suffix: }.

public static final String
DEFAULT_VALUE_SEPARATOR

Default value separator: :.

protected boolean
protected String
protected String
placeholderPrefix

Defaults to ${.

protected String
placeholderSuffix

Defaults to }.

protected boolean
protected String
valueSeparator

Defaults to :.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
public void
setBeanFactory(BeanFactory
owning BeanFactory (never null). The bean can immediately call methods on the factory.
beanFactory
)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Only necessary to check that we're not parsing our own bean definition, to avoid failing on unresolvable placeholders in properties file locations.

public void
setBeanName(String
the name of the bean in the factory. Note that this name is the actual bean name used in the factory, which may differ from the originally specified name: in particular for inner bean names, the actual bean name might have been made unique through appending "#..." suffixes. Use the BeanFactoryUtils#originalBeanName(String) method to extract the original bean name (without suffix), if desired.
beanName
)

Implements org.springframework.beans.factory.BeanNameAware.setBeanName.

Only necessary to check that we're not parsing our own bean definition, to avoid failing on unresolvable placeholders in properties file locations.

public void
setIgnoreUnresolvablePlaceholders(boolean ignoreUnresolvablePlaceholders)

Set whether to ignore unresolvable placeholders.

public void
setNullValue(String nullValue)

Set a value that should be treated as null when resolved as a placeholder value: e.g. "" (empty String) or "null".

public void
setPlaceholderPrefix(String placeholderPrefix)

Set the prefix that a placeholder string starts with.

public void
setPlaceholderSuffix(String placeholderSuffix)

Set the suffix that a placeholder string ends with.

public void
setTrimValues(boolean trimValues)

Specify whether to trim resolved values before applying them, removing superfluous whitespace from the beginning and end.

public void
setValueSeparator(String valueSeparator)

Specify the separating character between the placeholder variable and the associated default value, or null if no such special character should be processed as a value separator.

Inherited from org.springframework.beans.factory.config.PropertyResourceConfigurer:
convertPropertiesconvertPropertyconvertPropertyValuegetOrderpostProcessBeanFactoryprocessPropertiessetOrder

Field Detail

beanFactoryback to summary
private BeanFactory beanFactory
Annotations
@Nullable
beanNameback to summary
private String beanName
Annotations
@Nullable
DEFAULT_PLACEHOLDER_PREFIXback to summary
public static final String DEFAULT_PLACEHOLDER_PREFIX

Default placeholder prefix: ${.

DEFAULT_PLACEHOLDER_SUFFIXback to summary
public static final String DEFAULT_PLACEHOLDER_SUFFIX

Default placeholder suffix: }.

DEFAULT_VALUE_SEPARATORback to summary
public static final String DEFAULT_VALUE_SEPARATOR

Default value separator: :.

ignoreUnresolvablePlaceholdersback to summary
protected boolean ignoreUnresolvablePlaceholders
nullValueback to summary
protected String nullValue
Annotations
@Nullable
placeholderPrefixback to summary
protected String placeholderPrefix

Defaults to ${.

placeholderSuffixback to summary
protected String placeholderSuffix

Defaults to }.

trimValuesback to summary
protected boolean trimValues
valueSeparatorback to summary
protected String valueSeparator

Defaults to :.

Annotations
@Nullable

Constructor Detail

PlaceholderConfigurerSupportback to summary
public PlaceholderConfigurerSupport()

Method Detail

doProcessPropertiesback to summary
protected void doProcessProperties(ConfigurableListableBeanFactory beanFactoryToProcess, StringValueResolver valueResolver)
setBeanFactoryback to summary
public void setBeanFactory(BeanFactory beanFactory)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Only necessary to check that we're not parsing our own bean definition, to avoid failing on unresolvable placeholders in properties file locations. The latter case can happen with placeholders for system properties in resource locations.

Parameters
beanFactory:BeanFactory

Doc from org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

owning BeanFactory (never null). The bean can immediately call methods on the factory.

Annotations
@Override
See Also
setLocations, org.springframework.core.io.ResourceEditor
setBeanNameback to summary
public void setBeanName(String beanName)

Implements org.springframework.beans.factory.BeanNameAware.setBeanName.

Only necessary to check that we're not parsing our own bean definition, to avoid failing on unresolvable placeholders in properties file locations. The latter case can happen with placeholders for system properties in resource locations.

Parameters
beanName:String

Doc from org.springframework.beans.factory.BeanNameAware.setBeanName.

the name of the bean in the factory. Note that this name is the actual bean name used in the factory, which may differ from the originally specified name: in particular for inner bean names, the actual bean name might have been made unique through appending "#..." suffixes. Use the BeanFactoryUtils#originalBeanName(String) method to extract the original bean name (without suffix), if desired.

Annotations
@Override
See Also
setLocations, org.springframework.core.io.ResourceEditor
setIgnoreUnresolvablePlaceholdersback to summary
public void setIgnoreUnresolvablePlaceholders(boolean ignoreUnresolvablePlaceholders)

Set whether to ignore unresolvable placeholders.

Default is "false": An exception will be thrown if a placeholder fails to resolve. Switch this flag to "true" in order to preserve the placeholder String as-is in such a case, leaving it up to other placeholder configurers to resolve it.

setNullValueback to summary
public void setNullValue(String nullValue)

Set a value that should be treated as null when resolved as a placeholder value: e.g. "" (empty String) or "null".

Note that this will only apply to full property values, not to parts of concatenated values.

By default, no such null value is defined. This means that there is no way to express null as a property value unless you explicitly map a corresponding value here.

setPlaceholderPrefixback to summary
public void setPlaceholderPrefix(String placeholderPrefix)

Set the prefix that a placeholder string starts with. The default is ${.

setPlaceholderSuffixback to summary
public void setPlaceholderSuffix(String placeholderSuffix)

Set the suffix that a placeholder string ends with. The default is }.

setTrimValuesback to summary
public void setTrimValues(boolean trimValues)

Specify whether to trim resolved values before applying them, removing superfluous whitespace from the beginning and end.

Default is false.

Since
4.3
setValueSeparatorback to summary
public void setValueSeparator(String valueSeparator)

Specify the separating character between the placeholder variable and the associated default value, or null if no such special character should be processed as a value separator. The default is :.