OnEnvironmentPrepared constructor

const OnEnvironmentPrepared()

Annotation to mark a method that should run when the application environment has been prepared, but before the context is loaded.

This is the earliest lifecycle hook in the startup sequence. It allows you to inspect or modify environment properties, configure logging, or validate profiles before the context is created.

The only acceptable method signatures are:

  • No-Arg: The method should not accept any arguments.
  • One-Arg: The method should accept a single argument of type ConfigurableEnvironment or ConfigurableBootstrapContext.
  • Two-Args: The method should accept two arguments of types ConfigurableEnvironment and ConfigurableBootstrapContext.

Example

class MyApp {
  @OnEnvironmentPrepared()
  void setupEnvironment() {
    print("Environment prepared, validating configuration...");
  }

  @OnEnvironmentPrepared()
  void setupEnvironmentWithEnvironment(ConfigurableEnvironment environment) {
    print("Environment prepared, validating configuration...");
  }

  @OnEnvironmentPrepared()
  void setupEnvironmentWithEnvironmentAndBootstrapContext(ConfigurableEnvironment environment, ConfigurableBootstrapContext bootstrapContext) {
    print("Environment prepared, validating configuration...");
  }

  @OnEnvironmentPrepared()
  void setupEnvironmentWithBootstrapContext(ConfigurableBootstrapContext bootstrapContext) {
    print("Environment prepared, validating configuration...");
  }
}

Implementation

const OnEnvironmentPrepared();