Class ApplicationEnvironmentPropertiesSource

java.lang.Object
io.fluxcapacitor.common.application.JavaPropertiesSource
io.fluxcapacitor.common.application.ApplicationEnvironmentPropertiesSource
All Implemented Interfaces:
PropertySource

public class ApplicationEnvironmentPropertiesSource extends JavaPropertiesSource
A PropertySource that loads environment-specific properties from an application-<env>.properties file on the classpath.

This is commonly used for supporting configuration overrides based on the deployment environment (e.g. dev, staging, production).

The environment name is resolved from system environment variables or system properties, in the following order of precedence:

  1. ENVIRONMENT environment variable
  2. environment environment variable
  3. ENVIRONMENT system property
  4. environment system property

For example, if the environment is resolved as staging, this class attempts to load and merge all matching application-staging.properties files from the classpath. If no environment is specified, this source remains empty and resolves no properties.

Example:

 # application-staging.properties
 flux.url=https://staging.api.example.com
 flux.debug=true
 

This class complements ApplicationPropertiesSource for layered configuration. Typically, general values are defined in application.properties, while environment-specific values override them via application-<env>.properties.

This class uses FileUtils.loadProperties(String) internally to support merging across modules, and warns when duplicate keys occur across files.

See Also:
  • Constructor Details

    • ApplicationEnvironmentPropertiesSource

      public ApplicationEnvironmentPropertiesSource()
      Constructs an ApplicationEnvironmentPropertiesSource based on the resolved environment. If no environment is configured, this source will be empty.
    • ApplicationEnvironmentPropertiesSource

      public ApplicationEnvironmentPropertiesSource(String environment)
      Constructs an ApplicationEnvironmentPropertiesSource using the specified environment name.
      Parameters:
      environment - the environment name (e.g., dev, prod); may be null.
  • Method Details

    • loadProperties

      protected static Properties loadProperties(String environment)
      Loads properties from an application-<env>.properties file if the environment name is present.
      Parameters:
      environment - the resolved environment
      Returns:
      the loaded properties, or an empty set if no environment was specified
    • getEnvironment

      protected static String getEnvironment()
      Attempts to resolve the active environment using environment variables or system properties.
      Returns:
      the resolved environment name, or null if not set