SpringApplicationEvent class abstract
A step of the application's start, announced to listeners.
Code sometimes has to act at a precise point of the start: after the config files are read but before any bean exists, or once the application is ready to serve. SpringApplication publishes one subclass of this event at each such point, in this order:
- ApplicationStartingEvent: the run has begun.
- ApplicationEnvironmentPreparedEvent: properties and profiles are known.
- ApplicationContextInitializedEvent and ApplicationPreparedEvent: the context exists, no bean is created yet.
- (the context's own
ContextRefreshedEvent: every bean is created.) - ApplicationStartedEvent: then the runners are called.
- ApplicationReadyEvent: the runners are done.
If the start or a runner fails, ApplicationFailedEvent is published instead of the rest.
Which listeners see which event matters. The events up to
ApplicationPreparedEvent happen before any bean exists, so an
@EventListener method never receives them; only listeners registered
on the application itself do (SpringApplication.addListener, or
listeners:). From ApplicationPreparedEvent on, those listeners are
also listeners of the context. ApplicationStartedEvent,
ApplicationReadyEvent and the ApplicationFailedEvent of a failing
runner go through the context, so @EventListener methods and
ApplicationListener beans receive them too. Most applications only
listen to ApplicationReadyEvent from a bean.
// Before any bean exists: only a listener on the application sees this.
void main(List<String> args) => (springApplication
..addListener<ApplicationEnvironmentPreparedEvent>(
(event) => log.info(event.environment.activeProfiles),
))
.run(args);
Spring (Java): SpringApplicationEvent, with the same events in the
same order.
- Inheritance
-
- Object
- ApplicationEvent
- SpringApplicationEvent
Constructors
-
SpringApplicationEvent(SpringApplication application, List<
String> args) -
An event of
application, run withargs. OnlySpringApplicationcreates these events; create one yourself only to test a listener.
Properties
-
args
→ List<
String> -
The arguments of the run, as
mainreceived them.final - eventName → String
-
The event's name in logs and in the debug timeline: its class's name
by default. A release build shortens class names (
minified:Class12), so an event that should be recognised there names itself, as the framework's do:no setterinherited - hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- source → Object
-
The object that raised the event, usually the publishing bean (or
the context, for the context's own events).
finalinherited
- springApplication → SpringApplication
-
The application being started; the same object as
source, with its type.no setter - timestamp → DateTime
-
When the event was created (not when a listener receives it).
finalinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited