Class ApplicationEnvironmentPropertiesSource
- All Implemented Interfaces:
PropertySource
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:
ENVIRONMENTenvironment variableenvironmentenvironment variableENVIRONMENTsystem propertyenvironmentsystem 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 fluxzero.url=https://staging.api.example.com fluxzero.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:
-
Field Summary
Fields inherited from interface PropertySource
substitutionPattern -
Constructor Summary
ConstructorsConstructorDescriptionConstructs anApplicationEnvironmentPropertiesSourcebased on the resolved environment.ApplicationEnvironmentPropertiesSource(String environment) Constructs anApplicationEnvironmentPropertiesSourceusing the specified environment name. -
Method Summary
Modifier and TypeMethodDescriptionprotected static StringAttempts to resolve the active environment using environment variables or system properties.protected static PropertiesloadProperties(String environment) Loads properties from anapplication-<env>.propertiesfile if the environment name is present.Methods inherited from class JavaPropertiesSource
getMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface PropertySource
andThen, containsProperty, get, getBoolean, getBoolean, require, substituteProperties, substituteProperties
-
Constructor Details
-
ApplicationEnvironmentPropertiesSource
public ApplicationEnvironmentPropertiesSource()Constructs anApplicationEnvironmentPropertiesSourcebased on the resolved environment. If no environment is configured, this source will be empty. -
ApplicationEnvironmentPropertiesSource
Constructs anApplicationEnvironmentPropertiesSourceusing the specified environment name.- Parameters:
environment- the environment name (e.g.,dev,prod); may benull.
-
-
Method Details
-
loadProperties
Loads properties from anapplication-<env>.propertiesfile 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
Attempts to resolve the active environment using environment variables or system properties.- Returns:
- the resolved environment name, or
nullif not set
-