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:mydbAnnotated 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}" />
PropertyPlaceholderConfigurer, org.springframework.context.support.PropertySourcesPlaceholderConfigurer
| Modifier and Type | Field 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 :. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected void | doProcessProperties(ConfigurableListableBeanFactory beanFactoryToProcess, StringValueResolver valueResolver)
|
| public void | setBeanFactory(BeanFactory
owning BeanFactory (never beanFactory)null).
The bean can immediately call methods on the factory.Implements org. 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 beanName)BeanFactoryUtils#originalBeanName(String)
method to extract the original bean name (without suffix), if desired.Implements org. 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 |
| public void | |
| public void | |
| 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 |
| beanFactory | back to summary |
|---|---|
| private BeanFactory beanFactory
| |
| beanName | back to summary |
|---|---|
| private String beanName
| |
| DEFAULT_PLACEHOLDER_PREFIX | back to summary |
|---|---|
| public static final String DEFAULT_PLACEHOLDER_PREFIX Default placeholder prefix: ${. | |
| DEFAULT_PLACEHOLDER_SUFFIX | back to summary |
|---|---|
| public static final String DEFAULT_PLACEHOLDER_SUFFIX Default placeholder suffix: }. | |
| DEFAULT_VALUE_SEPARATOR | back to summary |
|---|---|
| public static final String DEFAULT_VALUE_SEPARATOR Default value separator: :. | |
| ignoreUnresolvablePlaceholders | back to summary |
|---|---|
| protected boolean ignoreUnresolvablePlaceholders | |
| nullValue | back to summary |
|---|---|
| protected String nullValue
| |
| placeholderPrefix | back to summary |
|---|---|
| protected String placeholderPrefix Defaults to ${. | |
| placeholderSuffix | back to summary |
|---|---|
| protected String placeholderSuffix Defaults to }. | |
| trimValues | back to summary |
|---|---|
| protected boolean trimValues | |
| valueSeparator | back to summary |
|---|---|
| protected String valueSeparator Defaults to :. | |
| PlaceholderConfigurerSupport | back to summary |
|---|---|
| public PlaceholderConfigurerSupport() | |
| doProcessProperties | back to summary |
|---|---|
| protected void doProcessProperties(ConfigurableListableBeanFactory beanFactoryToProcess, StringValueResolver valueResolver) | |
| setBeanFactory | back to summary |
|---|---|
| public void setBeanFactory(BeanFactory beanFactory) Implements org. 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.
| |
| setBeanName | back to summary |
|---|---|
| public void setBeanName(String beanName) Implements org. 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.
| |
| setIgnoreUnresolvablePlaceholders | back 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. | |
| setNullValue | back to summary |
|---|---|
| public void setNullValue(String nullValue) Set a value that should be treated as 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 | |
| setPlaceholderPrefix | back to summary |
|---|---|
| public void setPlaceholderPrefix(String placeholderPrefix) Set the prefix that a placeholder string starts with. The default is ${. | |
| setPlaceholderSuffix | back to summary |
|---|---|
| public void setPlaceholderSuffix(String placeholderSuffix) Set the suffix that a placeholder string ends with. The default is }. | |
| setTrimValues | back 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
| |
| setValueSeparator | back to summary |
|---|---|
| public void setValueSeparator(String valueSeparator) Specify the separating character between the placeholder variable
and the associated default value, or | |