Class PropertyResourceConfigurer

java.lang.Object
org.springframework.core.io.support.PropertiesLoaderSupport
org.springframework.beans.factory.config.PropertyResourceConfigurer
All Implemented Interfaces:
BeanFactoryPostProcessor, org.springframework.core.Ordered, org.springframework.core.PriorityOrdered
Direct Known Subclasses:
PlaceholderConfigurerSupport, PropertyOverrideConfigurer

public abstract class PropertyResourceConfigurer extends org.springframework.core.io.support.PropertiesLoaderSupport implements BeanFactoryPostProcessor, org.springframework.core.PriorityOrdered
Allows for configuration of individual bean property values from a property resource, i.e. a properties file. Useful for custom config files targeted at system administrators that override bean properties configured in the application context.

Two concrete implementations are provided in the distribution:

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.

Since:
02.10.2003
Author:
Juergen Hoeller
See Also:
  • Field Summary

    Fields inherited from class org.springframework.core.io.support.PropertiesLoaderSupport

    localOverride, localProperties, logger

    Fields inherited from interface org.springframework.core.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Convert the given merged properties, converting property values if necessary.
    protected String
    convertProperty(String propertyName, String propertyValue)
    Convert the given property from the properties source to the value which should be applied.
    protected String
    Convert the given property value from the properties source to the value which should be applied.
    int
     
    void
    Merge, convert and process properties against the given bean factory.
    protected abstract void
    Apply the given Properties to the given BeanFactory.
    void
    setOrder(int order)
    Set the order value of this object for sorting purposes.

    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
  • Constructor Details

    • PropertyResourceConfigurer

      public PropertyResourceConfigurer()
  • Method Details

    • setOrder

      public void setOrder(int order)
      Set the order value of this object for sorting purposes.
      See Also:
      • PriorityOrdered
    • getOrder

      public int getOrder()
      Specified by:
      getOrder in interface org.springframework.core.Ordered
    • postProcessBeanFactory

      public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException
      Merge, convert and process properties against the given bean factory.
      Specified by:
      postProcessBeanFactory in interface BeanFactoryPostProcessor
      Parameters:
      beanFactory - the bean factory used by the application context
      Throws:
      BeanInitializationException - if any properties cannot be loaded
      BeansException - in case of errors
    • convertProperties

      protected void convertProperties(Properties props)
      Convert the given merged properties, converting property values if necessary. The result will then be processed.

      The default implementation will invoke convertPropertyValue(java.lang.String) for each property value, replacing the original with the converted value.

      Parameters:
      props - the Properties to convert
      See Also:
    • convertProperty

      protected String convertProperty(String propertyName, String propertyValue)
      Convert the given property from the properties source to the value which should be applied.

      The default implementation calls convertPropertyValue(String).

      Parameters:
      propertyName - the name of the property that the value is defined for
      propertyValue - the original value from the properties source
      Returns:
      the converted value, to be used for processing
      See Also:
    • convertPropertyValue

      protected String convertPropertyValue(String originalValue)
      Convert the given property value from the properties source to the value which should be applied.

      The default implementation simply returns the original value. Can be overridden in subclasses, for example to detect encrypted values and decrypt them accordingly.

      Parameters:
      originalValue - the original value from the properties source (properties file or local "properties")
      Returns:
      the converted value, to be used for processing
      See Also:
      • PropertiesLoaderSupport.setProperties(java.util.Properties)
      • PropertiesLoaderSupport.setLocations(org.springframework.core.io.Resource...)
      • PropertiesLoaderSupport.setLocation(org.springframework.core.io.Resource)
      • convertProperty(String, String)
    • processProperties

      protected abstract void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props) throws BeansException
      Apply the given Properties to the given BeanFactory.
      Parameters:
      beanFactory - the BeanFactory used by the application context
      props - the Properties to apply
      Throws:
      BeansException - in case of errors