OnApplicationStarted constructor
const
OnApplicationStarted()
Annotation to mark a method that should run when the application has started, meaning the context is refreshed but the app is not yet fully ready.
This is commonly used to register services, trigger warm-up tasks, or perform actions that depend on the refreshed context.
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
ConfigurableApplicationContext
orDuration
. - Two-Args: The method should accept two arguments of types
ConfigurableApplicationContext
andDuration
.
Example
class MyApp {
@OnApplicationStarted()
void afterStart() {
print("Application context has started, initializing caches...");
}
@OnApplicationStarted()
void afterStartWithContext(ConfigurableApplicationContext context) {
print("Application context has started, initializing caches...");
}
@OnApplicationStarted()
void afterStartWithContextAndTime(ConfigurableApplicationContext context, Duration timeTaken) {
print("Application context has started, initializing caches...");
}
@OnApplicationStarted()
void afterStartWithTime(Duration timeTaken) {
print("Application context has started, initializing caches...");
}
}
Implementation
const OnApplicationStarted();