|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.core.io.support.PropertiesLoaderSupport
org.springframework.beans.factory.config.PropertyResourceConfigurer
org.springframework.beans.factory.config.PropertyOverrideConfigurer
public class PropertyOverrideConfigurer
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=valueExample properties file:
dataSource.driverClassName=com.mysql.jdbc.Driver dataSource.url=jdbc:mysql:mydbIn 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. Furthermore, note that specified override values are always literal values; they are not translated into bean references. This also applies when the original value in the XML bean definition specifies a bean reference.
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.
PropertyResourceConfigurer.convertPropertyValue(java.lang.String)
,
PropertyPlaceholderConfigurer
Field Summary | |
---|---|
private java.util.Set<java.lang.String> |
beanNames
Contains names of beans that have overrides |
private java.lang.String |
beanNameSeparator
|
static java.lang.String |
DEFAULT_BEAN_NAME_SEPARATOR
|
private boolean |
ignoreInvalidKeys
|
Fields inherited from class org.springframework.core.io.support.PropertiesLoaderSupport |
---|
localOverride, localProperties, logger, XML_FILE_EXTENSION |
Fields inherited from interface org.springframework.core.Ordered |
---|
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE |
Constructor Summary | |
---|---|
PropertyOverrideConfigurer()
|
Method Summary | |
---|---|
protected void |
applyPropertyValue(ConfigurableListableBeanFactory factory,
java.lang.String beanName,
java.lang.String property,
java.lang.String value)
Apply the given property value to the corresponding bean. |
boolean |
hasPropertyOverridesFor(java.lang.String beanName)
Were there overrides for this bean? Only valid after processing has occurred at least once. |
protected void |
processKey(ConfigurableListableBeanFactory factory,
java.lang.String key,
java.lang.String value)
Process the given key as 'beanName.property' entry. |
protected void |
processProperties(ConfigurableListableBeanFactory beanFactory,
java.util.Properties props)
Apply the given Properties to the given BeanFactory. |
void |
setBeanNameSeparator(java.lang.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, convertProperty, 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 |
---|
public static final java.lang.String DEFAULT_BEAN_NAME_SEPARATOR
private java.lang.String beanNameSeparator
private boolean ignoreInvalidKeys
private java.util.Set<java.lang.String> beanNames
Constructor Detail |
---|
public PropertyOverrideConfigurer()
Method Detail |
---|
public void setBeanNameSeparator(java.lang.String beanNameSeparator)
public void setIgnoreInvalidKeys(boolean ignoreInvalidKeys)
If you ignore invalid keys, keys that do not follow the 'beanName.property' format (or refer to invalid bean names or properties) will just be logged at debug level. This allows one to have arbitrary other keys in a properties file.
protected void processProperties(ConfigurableListableBeanFactory beanFactory, java.util.Properties props) throws BeansException
PropertyResourceConfigurer
processProperties
in class PropertyResourceConfigurer
beanFactory
- the BeanFactory used by the application contextprops
- the Properties to apply
BeansException
- in case of errorsprotected void processKey(ConfigurableListableBeanFactory factory, java.lang.String key, java.lang.String value) throws BeansException
BeansException
protected void applyPropertyValue(ConfigurableListableBeanFactory factory, java.lang.String beanName, java.lang.String property, java.lang.String value)
public boolean hasPropertyOverridesFor(java.lang.String beanName)
beanName
- name of the bean to query status for
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |