public abstract class

PlaceholderConfigurerSupport

extends PropertyResourceConfigurer
implements BeanFactoryAware BeanNameAware
java.lang.Object
   ↳ org.springframework.core.io.support.PropertiesLoaderSupport
     ↳ org.springframework.beans.factory.config.PropertyResourceConfigurer
       ↳ org.springframework.beans.factory.config.PlaceholderConfigurerSupport
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

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}{@code"/>  
}
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 default value separator which is ":" by default and customizable via setValueSeparator(String).

Example XML property with default value:

<property name="url" value="jdbc:${dbname:defaultdb}{@code"/> }

Summary

Constants
String DEFAULT_PLACEHOLDER_PREFIX Default placeholder prefix: {@value }
String DEFAULT_PLACEHOLDER_SUFFIX Default placeholder suffix: {@value }
String DEFAULT_VALUE_SEPARATOR Default value separator: {@value }
[Expand]
Inherited Constants
From class org.springframework.core.io.support.PropertiesLoaderSupport
From interface org.springframework.core.Ordered
Fields
protected boolean ignoreUnresolvablePlaceholders
protected String nullValue
protected String placeholderPrefix Defaults to {@value #DEFAULT_PLACEHOLDER_PREFIX}
protected String placeholderSuffix Defaults to {@value #DEFAULT_PLACEHOLDER_SUFFIX}
protected String valueSeparator Defaults to {@value #DEFAULT_VALUE_SEPARATOR}
[Expand]
Inherited Fields
From class org.springframework.core.io.support.PropertiesLoaderSupport
Public Constructors
PlaceholderConfigurerSupport()
Public Methods
void setBeanFactory(BeanFactory beanFactory)
Only necessary to check that we're not parsing our own bean definition, to avoid failing on unresolvable placeholders in properties file locations.
void setBeanName(String beanName)
Only necessary to check that we're not parsing our own bean definition, to avoid failing on unresolvable placeholders in properties file locations.
void setIgnoreUnresolvablePlaceholders(boolean ignoreUnresolvablePlaceholders)
Set whether to ignore unresolvable placeholders.
void setNullValue(String nullValue)
Set a value that should be treated as null when resolved as a placeholder value: e.g.
void setPlaceholderPrefix(String placeholderPrefix)
Set the prefix that a placeholder string starts with.
void setPlaceholderSuffix(String placeholderSuffix)
Set the suffix that a placeholder string ends with.
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.
Protected Methods
void doProcessProperties(ConfigurableListableBeanFactory beanFactoryToProcess, StringValueResolver valueResolver)
[Expand]
Inherited Methods
From class org.springframework.beans.factory.config.PropertyResourceConfigurer
From class org.springframework.core.io.support.PropertiesLoaderSupport
From class java.lang.Object
From interface org.springframework.beans.factory.BeanFactoryAware
From interface org.springframework.beans.factory.BeanNameAware
From interface org.springframework.beans.factory.config.BeanFactoryPostProcessor
From interface org.springframework.core.Ordered

Constants

public static final String DEFAULT_PLACEHOLDER_PREFIX

Also: SpringBeans

Default placeholder prefix: {@value }

Constant Value: "${"

public static final String DEFAULT_PLACEHOLDER_SUFFIX

Also: SpringBeans

Default placeholder suffix: {@value }

Constant Value: "}"

public static final String DEFAULT_VALUE_SEPARATOR

Also: SpringBeans

Default value separator: {@value }

Constant Value: ":"

Fields

protected boolean ignoreUnresolvablePlaceholders

Also: SpringBeans

protected String nullValue

Also: SpringBeans

protected String placeholderPrefix

Also: SpringBeans

Defaults to {@value #DEFAULT_PLACEHOLDER_PREFIX}

protected String placeholderSuffix

Also: SpringBeans

Defaults to {@value #DEFAULT_PLACEHOLDER_SUFFIX}

protected String valueSeparator

Also: SpringBeans

Defaults to {@value #DEFAULT_VALUE_SEPARATOR}

Public Constructors

public PlaceholderConfigurerSupport ()

Also: SpringBeans

Public Methods

public void setBeanFactory (BeanFactory beanFactory)

Also: SpringBeans

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 owning BeanFactory (never null). The bean can immediately call methods on the factory.

public void setBeanName (String beanName)

Also: SpringBeans

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

public void setIgnoreUnresolvablePlaceholders (boolean ignoreUnresolvablePlaceholders)

Also: SpringBeans

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.

public void setNullValue (String nullValue)

Also: SpringBeans

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.

public void setPlaceholderPrefix (String placeholderPrefix)

Also: SpringBeans

Set the prefix that a placeholder string starts with. The default is {@value #DEFAULT_PLACEHOLDER_PREFIX}.

public void setPlaceholderSuffix (String placeholderSuffix)

Also: SpringBeans

Set the suffix that a placeholder string ends with. The default is {@value #DEFAULT_PLACEHOLDER_SUFFIX}.

public void setValueSeparator (String valueSeparator)

Also: SpringBeans

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 {@value #DEFAULT_VALUE_SEPARATOR}.

Protected Methods

protected void doProcessProperties (ConfigurableListableBeanFactory beanFactoryToProcess, StringValueResolver valueResolver)