org.springframework.beans.factory.config
Class PropertyPlaceholderConfigurer

org.springframework.beans.factory.config.PropertyResourceConfigurer
  |
  +--org.springframework.beans.factory.config.PropertyPlaceholderConfigurer

public class PropertyPlaceholderConfigurer
extends PropertyResourceConfigurer

A property resource configurer that resolves placeholders in bean property values of context definitions. It pulls values from a properties file into bean definitions.

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

  ${...}

Example XML context definition:

  <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName"><value>${driver}</value></property>
    <property name="url"><value>jdbc:${dbname}</value></property>
  </bean>

Example properties file:

  driver=com.mysql.jdbc.Driver
  dbname=mysql:mydb

PropertyPlaceholderConfigurer checks 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, this configurer allows to fill in explicit placeholders in context definitions. Therefore, the original definition cannot specify any default values for such bean properties, and the placeholder properties file is supposed to contain an entry for each defined placeholder.

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" setting. You can also define multiple PropertyPlaceholderConfigurers, each with its own placeholder syntax.

Default property values can be defined via "properties", to make overriding definitions in properties files optional. A configurer will also check against system properties (e.g. "user.dir") if it cannot resolve a placeholder with any of the specified properties. This can be turned off via "checkSystemProperties".

Note that the context definition is aware of being incomplete; this is immediately obvious when looking at the XML definition file.

Author:
Juergen Hoeller
Since: 02.10.2003
See Also: PropertyOverrideConfigurer, PropertyResourceConfigurer.setLocations(org.springframework.core.io.Resource[]), PropertyResourceConfigurer.setProperties(java.util.Properties), setPlaceholderPrefix(java.lang.String), setPlaceholderSuffix(java.lang.String), setCheckSystemProperties(boolean), java.lang.System.getProperty(java.lang.String)

Field Summary
 final static StringDEFAULT_PLACEHOLDER_PREFIX
           
 final static StringDEFAULT_PLACEHOLDER_SUFFIX
           

Method Summary
 voidsetCheckSystemProperties(boolean checkSystemProperties)
          Whether to check system properties if not being able to resolve a placeholder with the specified properties.
 voidsetPlaceholderPrefix(String placeholderPrefix)
          Set the prefix that a placeholder string starts with.
 voidsetPlaceholderSuffix(String placeholderSuffix)
          Set the suffix that a placeholder string ends with.

Methods inherited from class org.springframework.beans.factory.config.PropertyResourceConfigurer
getOrder, postProcessBeanFactory, setIgnoreResourceNotFound, setLocation, setLocations, setOrder, setProperties

Field Detail

DEFAULT_PLACEHOLDER_PREFIX

public final static String DEFAULT_PLACEHOLDER_PREFIX

DEFAULT_PLACEHOLDER_SUFFIX

public final static String DEFAULT_PLACEHOLDER_SUFFIX
Method Detail

setCheckSystemProperties

public void setCheckSystemProperties(boolean checkSystemProperties)
Whether to check system properties if not being able to resolve a placeholder with the specified properties. For example, will resolve ${user.dir} to the "user.dir" system property (if not overridden in the specified properties).

Default is true.


setPlaceholderPrefix

public void setPlaceholderPrefix(String placeholderPrefix)
Set the prefix that a placeholder string starts with. The default is "${".
See Also:
DEFAULT_PLACEHOLDER_PREFIX

setPlaceholderSuffix

public void setPlaceholderSuffix(String placeholderSuffix)
Set the suffix that a placeholder string ends with. The default is "}".
See Also:
DEFAULT_PLACEHOLDER_SUFFIX

Association Links

to Class java.lang.String

to Class java.lang.String

to Class java.lang.String

to Class java.lang.String