EnvironmentAware class abstract interface

Implemented by an object that wants the configuration (properties and profiles) handed to it through a method call.

A bean can simply inject Environment. This callback matters for objects the container creates but does not inject: an ImportSelector or a registrar, which decide from the configuration which beans to add. The context calls setEnvironment after injection and before the init callbacks; for a selector or registrar, before it runs.

// Reads feature switches from the configuration.
@Component()
class FeatureFlags implements EnvironmentAware {
  late Environment env;

  @override
  void setEnvironment(Environment environment) => env = environment;
}

Spring (Java):

@Component
class FeatureFlags implements EnvironmentAware {
  public void setEnvironment(Environment environment) { ... }
}
Implemented types

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setEnvironment(Environment environment) → void
Receives the context's environment; called once, after injection and before the init callbacks.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited