Interface PropertySource

All Known Implementing Classes:
ApplicationEnvironmentPropertiesSource, ApplicationPropertiesSource, DecryptingPropertySource, DefaultPropertySource, EnvironmentVariablesSource, JavaPropertiesSource, NoOpPropertySource, SimplePropertySource, SpringPropertySource, SystemPropertiesSource
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface PropertySource
Represents a source of configuration properties.

This interface provides a unified way to access application-level configuration values. You can use it to retrieve string, boolean, or substituted values and chain multiple sources together.

Implementations may load properties from system environment variables, property files, Spring contexts, application Entities, etc.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Pattern
    Regex pattern used for property substitution in the form ${property.name[:default]}.
  • Method Summary

    Modifier and Type
    Method
    Description
    Combines this property source with another, returning the first non-null value found between the two.
    default boolean
    Checks if a property is defined.
    get(String name)
    Retrieves the value of a property by name.
    default String
    get(String name, String defaultValue)
    Returns the property value, or the given default if not present.
    default boolean
    Returns the value of the property as a boolean.
    default boolean
    getBoolean(String name, boolean defaultValue)
    Returns the value of the property as a boolean, falling back to a default if not present.
    join(PropertySource... propertySources)
    Joins multiple PropertySource instances into a single one.
    default String
    Retrieves the value of a property by name and throws if not present.
    default String
    Substitutes all placeholders of the form ${property[:default]} in the given template string.
  • Field Details

    • substitutionPattern

      static final Pattern substitutionPattern
      Regex pattern used for property substitution in the form ${property.name[:default]}.
  • Method Details

    • get

      String get(String name)
      Retrieves the value of a property by name.
      Parameters:
      name - the name of the property to look up
      Returns:
      the property value, or null if not found
    • getBoolean

      default boolean getBoolean(String name)
      Returns the value of the property as a boolean.
      Parameters:
      name - the name of the property to look up
      Returns:
      true if the value is "true" (case-insensitive), false otherwise or if not present
    • getBoolean

      default boolean getBoolean(String name, boolean defaultValue)
      Returns the value of the property as a boolean, falling back to a default if not present.
      Parameters:
      name - the name of the property
      defaultValue - the value to return if the property is not set
      Returns:
      the parsed boolean value, or defaultValue if not present
    • get

      default String get(String name, String defaultValue)
      Returns the property value, or the given default if not present.
      Parameters:
      name - the name of the property
      defaultValue - the fallback value to use if the property is not set
      Returns:
      the property value or the default
    • require

      default String require(String name)
      Retrieves the value of a property by name and throws if not present.
      Parameters:
      name - the name of the property
      Returns:
      the property value
      Throws:
      IllegalStateException - if the property is not found
    • containsProperty

      default boolean containsProperty(String name)
      Checks if a property is defined.
      Parameters:
      name - the name of the property
      Returns:
      true if the property is set, otherwise false
    • substituteProperties

      default String substituteProperties(String template)
      Substitutes all placeholders of the form ${property[:default]} in the given template string.

      Supports recursive substitutions and default fallback values (e.g. ${env:dev}).

      Parameters:
      template - the template containing substitutions
      Returns:
      the fully substituted string
    • andThen

      default PropertySource andThen(PropertySource next)
      Combines this property source with another, returning the first non-null value found between the two.

      If a property is not present in this source, it will delegate to the next.

      Parameters:
      next - the fallback property source
      Returns:
      a chained property source
    • join

      static PropertySource join(PropertySource... propertySources)
      Joins multiple PropertySource instances into a single one.

      The returned property source will resolve properties using the order of the given sources.

      Parameters:
      propertySources - the sources to join
      Returns:
      a combined PropertySource