Class PropertiesLoaderSupport

java.lang.Object
com.aspectran.utils.PropertiesLoaderSupport
Direct Known Subclasses:
PropertiesFactoryBean

public abstract class PropertiesLoaderSupport extends 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.

Created: 2025. 2. 18.

  • Constructor Details

    • PropertiesLoaderSupport

      public PropertiesLoaderSupport()
  • Method Details

    • setProperties

      public void setProperties(Properties properties)
      Set local properties, for example, 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(Properties... propertiesArray)
      Set local properties, for example, via the "props" tag in XML bean definitions, allowing for merging multiple properties sets into one.
    • setLocation

      public void setLocation(String 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 Java's properties XML format.

    • setLocations

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

      Can point to classic properties files or to XML files that follow Java'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.

    • setIgnoreInvalidResource

      public void setIgnoreInvalidResource(boolean ignoreInvalidResource)
      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 Properties mergeProperties() throws IOException
      Return a merged Properties instance containing both the loaded properties and properties set on this FactoryBean.
      Throws:
      IOException
    • loadProperties

      protected void loadProperties(Properties props) throws IOException
      Load properties into the given instance.
      Parameters:
      props - the Properties instance to load into
      Throws:
      IOException - in case of I/O errors
      See Also:
    • getResourceAsStream

      protected abstract InputStream getResourceAsStream(String location) throws IOException
      Throws:
      IOException