AbstractEnvironment.source constructor
Constructor with Pre-Created Sources
Initializes the environment with a caller-supplied MutablePropertySources list. This constructor is used internally and by subclasses that want to directly control the initial set and ordering of property sources.
Behavior
- Assigns the provided
propertySources
to the internal state. - Creates a resolver via createPropertyResolver.
- Calls customizePropertySources to allow further subclass modifications.
- Populates default profiles with reserved defaults.
Example
final customSources = MutablePropertySources();
final env = MyEnvironment.source(customSources);
Notes
- Typically used by framework code, not by application developers.
Base class for creating environment implementations in JetLeaf.
AbstractEnvironment
is a foundational implementation of ConfigurableEnvironment
that manages environment properties and profiles via:
- A MutablePropertySources collection,
- A PropertySourcesPropertyResolver for resolving properties,
- A
ConfigurableConversionService
for type conversions, - and support for placeholder resolution and profile activation.
Subclasses should override customizePropertySources to register their own sources, such as system properties, application config maps, or custom sources.
Example
class MyEnvironment extends AbstractEnvironment {
@override
void customizePropertySources(MutablePropertySources sources) {
sources.addLast(MapPropertySource('my-config', {
'server.port': '8080',
'debug': 'true',
}));
}
}
void main() {
final env = MyEnvironment();
print(env.getProperty('server.port')); // 8080
}
Profiles
JetLeaf supports both active and default profiles:
- Active profiles are those explicitly set using setActiveProfiles or addActiveProfile.
- Default profiles are used when no active profile is set, and can be configured using setDefaultProfiles.
A default profile name of "default"
is always used unless overridden.
System properties and environment
You can access system properties and environment variables using getSystemProperties
and getSystemEnvironment. To suppress access to System.getenv()
, set the
jetleaf.getenv.ignore
flag via JetLeafProperties
.
Implementation
@protected
AbstractEnvironment.source(MutablePropertySources propertySources) {
_propertySources = propertySources;
_propertyResolver = createPropertyResolver(propertySources);
customizePropertySources(propertySources);
_defaultProfiles.addAll(getReservedDefaultProfiles());
}