OnApplicationStarting constructor
const
OnApplicationStarting()
Annotation to mark a method that should run when the application is starting, before the context refresh occurs.
This is typically used to prepare resources, validate configuration, or perform setup tasks that need to run at the very beginning of the application lifecycle.
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
ConfigurableBootstrapContext
orClass<Object>
. - Two-Args: The method should accept two arguments of types
ConfigurableBootstrapContext
andClass<Object>
.
Example
class MyApp {
@OnApplicationStarting()
void initResources() {
print("Initializing resources before context refresh...");
}
@OnApplicationStarting()
void initResourcesWithContext(ConfigurableBootstrapContext context) {
print("Initializing resources before context refresh...");
}
@OnApplicationStarting()
void initResourcesWithContextAndClass(ConfigurableBootstrapContext context, Class<Object> mainClass) {
print("Initializing resources before context refresh...");
}
@OnApplicationStarting()
void initResourcesWithClass(Class<Object> mainClass) {
print("Initializing resources before context refresh...");
}
}
Implementation
const OnApplicationStarting();