| |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.springframework.beans.factory.config.PropertyResourceConfigurer | +--org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
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.
| Field Summary | |
final static String | DEFAULT_PLACEHOLDER_PREFIX |
final static String | DEFAULT_PLACEHOLDER_SUFFIX |
| Method Summary | |
void | setCheckSystemProperties(boolean checkSystemProperties)Whether to check system properties if not being able to resolve a placeholder with the specified properties. |
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. |
| Methods inherited from class org.springframework.beans.factory.config.PropertyResourceConfigurer |
getOrder, postProcessBeanFactory, setIgnoreResourceNotFound, setLocation, setLocations, setOrder, setProperties |
| Field Detail |
public final static String DEFAULT_PLACEHOLDER_PREFIX
public final static String DEFAULT_PLACEHOLDER_SUFFIX
| Method Detail |
public void setCheckSystemProperties(boolean checkSystemProperties)
Default is true.
public void setPlaceholderPrefix(String placeholderPrefix)
public void setPlaceholderSuffix(String placeholderSuffix)
| Association Links |
to Class java.lang.String
to Class java.lang.String
to Class java.lang.String
| |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||