Class PlaceholderConfigurerSupport
- All Implemented Interfaces:
- Aware,- BeanFactoryAware,- BeanNameAware,- BeanFactoryPostProcessor,- Ordered,- PriorityOrdered
- Direct Known Subclasses:
- PropertyPlaceholderConfigurer,- PropertySourcesPlaceholderConfigurer
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}" />
 - Since:
- 3.1
- Author:
- Chris Beams, Juergen Hoeller
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final CharacterDefault escape character:'\'.static final StringDefault placeholder prefix: "${".static final StringDefault placeholder suffix: "}".static final StringDefault value separator: ":".protected CharacterDefaults toDEFAULT_ESCAPE_CHARACTER.protected booleanprotected Stringprotected StringDefaults to "${".protected StringDefaults to "}".protected booleanprotected StringDefaults to ":".Fields inherited from class org.springframework.core.io.support.PropertiesLoaderSupportlocalOverride, localProperties, loggerFields inherited from interface org.springframework.core.OrderedHIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected voiddoProcessProperties(ConfigurableListableBeanFactory beanFactoryToProcess, StringValueResolver valueResolver) voidsetBeanFactory(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.voidsetBeanName(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.voidsetEscapeCharacter(Character escsEscapeCharacter) Specify the escape character to use to ignore placeholder prefix or value separator, ornullif no escaping should take place.voidsetIgnoreUnresolvablePlaceholders(boolean ignoreUnresolvablePlaceholders) Set whether to ignore unresolvable placeholders.voidsetNullValue(String nullValue) Set a value that should be treated asnullwhen resolved as a placeholder value: for example, "" (empty String) or "null".voidsetPlaceholderPrefix(String placeholderPrefix) Set the prefix that a placeholder string starts with.voidsetPlaceholderSuffix(String placeholderSuffix) Set the suffix that a placeholder string ends with.voidsetTrimValues(boolean trimValues) Specify whether to trim resolved values before applying them, removing superfluous whitespace from the beginning and end.voidsetValueSeparator(String valueSeparator) Specify the separating character between the placeholder variable and the associated default value, ornullif no such special character should be processed as a value separator.Methods inherited from class org.springframework.beans.factory.config.PropertyResourceConfigurerconvertProperties, convertProperty, convertPropertyValue, getOrder, postProcessBeanFactory, processProperties, setOrderMethods inherited from class org.springframework.core.io.support.PropertiesLoaderSupportloadProperties, mergeProperties, setFileEncoding, setIgnoreResourceNotFound, setLocalOverride, setLocation, setLocations, setProperties, setPropertiesArray, setPropertiesPersister
- 
Field Details- 
DEFAULT_PLACEHOLDER_PREFIXDefault placeholder prefix: "${".- See Also:
 
- 
DEFAULT_PLACEHOLDER_SUFFIXDefault placeholder suffix: "}".- See Also:
 
- 
DEFAULT_VALUE_SEPARATORDefault value separator: ":".- See Also:
 
- 
DEFAULT_ESCAPE_CHARACTERDefault escape character:'\'.
- 
placeholderPrefixDefaults to "${".
- 
placeholderSuffixDefaults to "}".
- 
valueSeparatorDefaults to ":".
- 
escapeCharacterDefaults toDEFAULT_ESCAPE_CHARACTER.
- 
trimValuesprotected boolean trimValues
- 
nullValue
- 
ignoreUnresolvablePlaceholdersprotected boolean ignoreUnresolvablePlaceholders
 
- 
- 
Constructor Details- 
PlaceholderConfigurerSupportpublic PlaceholderConfigurerSupport()
 
- 
- 
Method Details- 
setPlaceholderPrefixSet the prefix that a placeholder string starts with. The default is "${".
- 
setPlaceholderSuffixSet the suffix that a placeholder string ends with. The default is "}".
- 
setValueSeparatorSpecify the separating character between the placeholder variable and the associated default value, ornullif no such special character should be processed as a value separator. The default is ":".
- 
setEscapeCharacterSpecify the escape character to use to ignore placeholder prefix or value separator, ornullif no escaping should take place.Default is DEFAULT_ESCAPE_CHARACTER.- Since:
- 6.2
 
- 
setTrimValuespublic 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
 
- 
setNullValueSet a value that should be treated asnullwhen resolved as a placeholder value: for example, "" (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 nullas a property value unless you explicitly map a corresponding value here.
- 
setIgnoreUnresolvablePlaceholderspublic 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. 
- 
setBeanNameOnly 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.- Specified by:
- setBeanNamein interface- BeanNameAware
- 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.
- See Also:
 
- 
setBeanFactoryOnly 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.- Specified by:
- setBeanFactoryin interface- BeanFactoryAware
- Parameters:
- beanFactory- owning BeanFactory (never- null). The bean can immediately call methods on the factory.
- See Also:
 
- 
doProcessPropertiesprotected void doProcessProperties(ConfigurableListableBeanFactory beanFactoryToProcess, StringValueResolver valueResolver) 
 
-