public abstract class PropertyResourceConfigurer extends PropertiesLoaderSupport implements BeanFactoryPostProcessor, PriorityOrdered
Two concrete implementations are provided in the distribution:
PropertyOverrideConfigurer
for "beanName.property=value" style overriding
(pushing values from a properties file into bean definitions)
PropertyPlaceholderConfigurer
for replacing "${...}" placeholders
(pulling values from a properties file into bean definitions)
Property values can be converted after reading them in, through overriding
the convertPropertyValue(java.lang.String)
method. For example, encrypted values
can be detected and decrypted accordingly before processing them.
PropertyOverrideConfigurer
,
PropertyPlaceholderConfigurer
localOverride, localProperties, logger
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
PropertyResourceConfigurer() |
Modifier and Type | Method and Description |
---|---|
protected void |
convertProperties(java.util.Properties props)
Convert the given merged properties, converting property values
if necessary.
|
protected java.lang.String |
convertProperty(java.lang.String propertyName,
java.lang.String propertyValue)
Convert the given property from the properties source to the value
which should be applied.
|
protected java.lang.String |
convertPropertyValue(java.lang.String originalValue)
Convert the given property value from the properties source to the value
which should be applied.
|
int |
getOrder()
Get the order value of this object.
|
void |
postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
|
protected abstract void |
processProperties(ConfigurableListableBeanFactory beanFactory,
java.util.Properties props)
Apply the given Properties to the given BeanFactory.
|
void |
setOrder(int order)
Set the order value of this object for sorting purposes.
|
loadProperties, mergeProperties, setFileEncoding, setIgnoreResourceNotFound, setLocalOverride, setLocation, setLocations, setProperties, setPropertiesArray, setPropertiesPersister
public void setOrder(int order)
PriorityOrdered
public int getOrder()
Ordered
Higher values are interpreted as lower priority. As a consequence,
the object with the lowest value has the highest priority (somewhat
analogous to Servlet load-on-startup
values).
Same order values will result in arbitrary sort positions for the affected objects.
getOrder
in interface Ordered
Ordered.HIGHEST_PRECEDENCE
,
Ordered.LOWEST_PRECEDENCE
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException
postProcessBeanFactory
in interface BeanFactoryPostProcessor
beanFactory
- the bean factory used by the application contextBeanInitializationException
- if any properties cannot be loadedBeansException
- in case of errorsprotected void convertProperties(java.util.Properties props)
The default implementation will invoke convertPropertyValue(java.lang.String)
for each property value, replacing the original with the converted value.
props
- the Properties to convertprocessProperties(org.springframework.beans.factory.config.ConfigurableListableBeanFactory, java.util.Properties)
protected java.lang.String convertProperty(java.lang.String propertyName, java.lang.String propertyValue)
The default implementation calls convertPropertyValue(String)
.
propertyName
- the name of the property that the value is defined forpropertyValue
- the original value from the properties sourceconvertPropertyValue(String)
protected java.lang.String convertPropertyValue(java.lang.String originalValue)
The default implementation simply returns the original value. Can be overridden in subclasses, for example to detect encrypted values and decrypt them accordingly.
originalValue
- the original value from the properties source
(properties file or local "properties")PropertiesLoaderSupport.setProperties(java.util.Properties)
,
PropertiesLoaderSupport.setLocations(org.springframework.core.io.Resource...)
,
PropertiesLoaderSupport.setLocation(org.springframework.core.io.Resource)
,
convertProperty(String, String)
protected abstract void processProperties(ConfigurableListableBeanFactory beanFactory, java.util.Properties props) throws BeansException
beanFactory
- the BeanFactory used by the application contextprops
- the Properties to applyBeansException
- in case of errors