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:
ENVIRONMENT
environment variableenvironment
environment variableENVIRONMENT
system propertyenvironment
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:
-
Field Summary
Fields inherited from interface io.fluxcapacitor.common.application.PropertySource
substitutionPattern
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs anApplicationEnvironmentPropertiesSource
based on the resolved environment.ApplicationEnvironmentPropertiesSource
(String environment) Constructs anApplicationEnvironmentPropertiesSource
using the specified environment name. -
Method Summary
Modifier and TypeMethodDescriptionprotected static String
Attempts to resolve the active environment using environment variables or system properties.protected static Properties
loadProperties
(String environment) Loads properties from anapplication-<env>.properties
file if the environment name is present.Methods inherited from class io.fluxcapacitor.common.application.JavaPropertiesSource
get
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.common.application.PropertySource
andThen, containsProperty, get, getBoolean, getBoolean, require, substituteProperties
-
Constructor Details
-
ApplicationEnvironmentPropertiesSource
public ApplicationEnvironmentPropertiesSource()Constructs anApplicationEnvironmentPropertiesSource
based on the resolved environment. If no environment is configured, this source will be empty. -
ApplicationEnvironmentPropertiesSource
Constructs anApplicationEnvironmentPropertiesSource
using the specified environment name.- Parameters:
environment
- the environment name (e.g.,dev
,prod
); may benull
.
-
-
Method Details
-
loadProperties
Loads properties from anapplication-<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
Attempts to resolve the active environment using environment variables or system properties.- Returns:
- the resolved environment name, or
null
if not set
-