org.springframework.beans.factory.config
Class PropertyOverrideConfigurer

java.lang.Object
  extended by org.springframework.core.io.support.PropertiesLoaderSupport
      extended by org.springframework.beans.factory.config.PropertyResourceConfigurer
          extended by org.springframework.beans.factory.config.PropertyOverrideConfigurer
All Implemented Interfaces:
BeanFactoryPostProcessor, Ordered

public class PropertyOverrideConfigurer
extends PropertyResourceConfigurer

A property resource configurer that overrides bean property values in an application context definition. It pushes values from a properties file into bean definitions.

Configuration lines are expected to be of the following form:

 beanName.property=value
Example properties file:
 dataSource.driverClassName=com.mysql.jdbc.Driver
 dataSource.url=jdbc:mysql:mydb
In contrast to PropertyPlaceholderConfigurer, the original definition can have default values or no values at all for such bean properties. If an overriding properties file does not have an entry for a certain bean property, the default context definition is used.

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

In case of multiple PropertyOverrideConfigurers that define different values for the same bean property, the last one will win (due to the overriding mechanism).

Property values can be converted after reading them in, through overriding the convertPropertyValue method. For example, encrypted values can be detected and decrypted accordingly before processing them.

Since:
12.03.2003
Author:
Juergen Hoeller, Rod Johnson
See Also:
PropertyResourceConfigurer.convertPropertyValue(java.lang.String), PropertyPlaceholderConfigurer

Field Summary
static String DEFAULT_BEAN_NAME_SEPARATOR
           
 
Fields inherited from class org.springframework.core.io.support.PropertiesLoaderSupport
logger, XML_FILE_EXTENSION
 
Constructor Summary
PropertyOverrideConfigurer()
           
 
Method Summary
protected  void applyPropertyValue(ConfigurableListableBeanFactory factory, String beanName, String property, String value)
          Apply the given property value to the corresponding bean.
 boolean hasPropertyOverridesFor(String beanName)
          Were there overrides for this bean?
protected  void processKey(ConfigurableListableBeanFactory factory, String key, String value)
          Process the given key as 'beanName.property' entry.
protected  void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)
          Apply the given Properties to the bean factory.
 void setBeanNameSeparator(String beanNameSeparator)
          Set the separator to expect between bean name and property path.
 void setIgnoreInvalidKeys(boolean ignoreInvalidKeys)
          Set whether to ignore invalid keys.
 
Methods inherited from class org.springframework.beans.factory.config.PropertyResourceConfigurer
convertProperties, convertPropertyValue, getOrder, postProcessBeanFactory, setOrder
 
Methods inherited from class org.springframework.core.io.support.PropertiesLoaderSupport
loadProperties, mergeProperties, setFileEncoding, setIgnoreResourceNotFound, setLocalOverride, setLocation, setLocations, setProperties, setPropertiesArray, setPropertiesPersister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BEAN_NAME_SEPARATOR

public static final String DEFAULT_BEAN_NAME_SEPARATOR
See Also:
Constant Field Values
Constructor Detail

PropertyOverrideConfigurer

public PropertyOverrideConfigurer()
Method Detail

setBeanNameSeparator

public void setBeanNameSeparator(String beanNameSeparator)
Set the separator to expect between bean name and property path. Default is a dot (".").


setIgnoreInvalidKeys

public void setIgnoreInvalidKeys(boolean ignoreInvalidKeys)
Set whether to ignore invalid keys. Default is "false".

If you ignore invalid keys, keys that do not follow the 'beanName.property' format will just be logged as warning. This allows to have arbitrary other keys in a properties file.


processProperties

protected void processProperties(ConfigurableListableBeanFactory beanFactory,
                                 Properties props)
                          throws BeansException
Description copied from class: PropertyResourceConfigurer
Apply the given Properties to the bean factory.

Specified by:
processProperties in class PropertyResourceConfigurer
Parameters:
beanFactory - the bean factory used by the application context
props - the Properties to apply
Throws:
BeansException - in case of errors

processKey

protected void processKey(ConfigurableListableBeanFactory factory,
                          String key,
                          String value)
                   throws BeansException
Process the given key as 'beanName.property' entry.

Throws:
BeansException

applyPropertyValue

protected void applyPropertyValue(ConfigurableListableBeanFactory factory,
                                  String beanName,
                                  String property,
                                  String value)
Apply the given property value to the corresponding bean.


hasPropertyOverridesFor

public boolean hasPropertyOverridesFor(String beanName)
Were there overrides for this bean? Only valid after processing has occurred at least once.

Parameters:
beanName - name of the bean to query status for
Returns:
whether there were property overrides for the named bean


Copyright (c) 2002-2007 The Spring Framework Project.