org.springframework.core.io.support

Class PropertiesLoaderSupport

  • java.lang.Object
    • org.springframework.core.io.support.PropertiesLoaderSupport
  • Direct Known Subclasses:
    PropertiesFactoryBean, PropertyResourceConfigurer


    public abstract class PropertiesLoaderSupport
    extends java.lang.Object
    Base class for JavaBean-style components that need to load properties from one or more resources. Supports local properties as well, with configurable overriding.
    Since:
    1.2.2
    Author:
    Juergen Hoeller
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      protected boolean localOverride 
      protected java.util.Properties[] localProperties 
      protected Log logger
      Logger available to subclasses.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      protected void loadProperties(java.util.Properties props)
      Load properties into the given instance.
      protected java.util.Properties mergeProperties()
      Return a merged Properties instance containing both the loaded properties and properties set on this FactoryBean.
      void setFileEncoding(java.lang.String encoding)
      Set the encoding to use for parsing properties files.
      void setIgnoreResourceNotFound(boolean ignoreResourceNotFound)
      Set if failure to find the property resource should be ignored.
      void setLocalOverride(boolean localOverride)
      Set whether local properties override properties from files.
      void setLocation(Resource location)
      Set a location of a properties file to be loaded.
      void setLocations(Resource... locations)
      Set locations of properties files to be loaded.
      void setProperties(java.util.Properties properties)
      Set local properties, e.g.
      void setPropertiesArray(java.util.Properties... propertiesArray)
      Set local properties, e.g.
      void setPropertiesPersister(PropertiesPersister propertiesPersister)
      Set the PropertiesPersister to use for parsing properties files.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • logger

        protected final Log logger
        Logger available to subclasses.
      • localProperties

        @Nullable
        protected java.util.Properties[] localProperties
      • localOverride

        protected boolean localOverride
    • Constructor Detail

      • PropertiesLoaderSupport

        public PropertiesLoaderSupport()
    • Method Detail

      • setProperties

        public void setProperties(java.util.Properties properties)
        Set local properties, e.g. via the "props" tag in XML bean definitions. These can be considered defaults, to be overridden by properties loaded from files.
      • setPropertiesArray

        public void setPropertiesArray(java.util.Properties... propertiesArray)
        Set local properties, e.g. via the "props" tag in XML bean definitions, allowing for merging multiple properties sets into one.
      • setLocation

        public void setLocation(Resource location)
        Set a location of a properties file to be loaded.

        Can point to a classic properties file or to an XML file that follows JDK 1.5's properties XML format.

      • setLocations

        public void setLocations(Resource... locations)
        Set locations of properties files to be loaded.

        Can point to classic properties files or to XML files that follow JDK 1.5's properties XML format.

        Note: Properties defined in later files will override properties defined earlier files, in case of overlapping keys. Hence, make sure that the most specific files are the last ones in the given list of locations.

      • setLocalOverride

        public void setLocalOverride(boolean localOverride)
        Set whether local properties override properties from files.

        Default is "false": Properties from files override local defaults. Can be switched to "true" to let local properties override defaults from files.

      • setIgnoreResourceNotFound

        public void setIgnoreResourceNotFound(boolean ignoreResourceNotFound)
        Set if failure to find the property resource should be ignored.

        "true" is appropriate if the properties file is completely optional. Default is "false".

      • mergeProperties

        protected java.util.Properties mergeProperties()
                                                throws java.io.IOException
        Return a merged Properties instance containing both the loaded properties and properties set on this FactoryBean.
        Throws:
        java.io.IOException
      • loadProperties

        protected void loadProperties(java.util.Properties props)
                               throws java.io.IOException
        Load properties into the given instance.
        Parameters:
        props - the Properties instance to load into
        Throws:
        java.io.IOException - in case of I/O errors
        See Also:
        setLocations(org.springframework.core.io.Resource...)