ContextClosedEvent class

Published when a context starts closing, while every bean is still available.

It is the first step of close(), before the lifecycle beans are stopped and the singletons destroyed. Listen to it to save state that needs other beans. An error thrown by a listener is logged and the shutdown goes on.

// Persists the sessions while the database bean still works.
@Component()
class SessionStore {
  @EventListener()
  void onClose(ContextClosedEvent event) => saveAll();
}

Spring (Java):

@EventListener
void onClose(ContextClosedEvent event) { saveAll(); }
Inheritance

Constructors

ContextClosedEvent(ApplicationContext source)
Creates the event for the context source; contexts do this.

Properties

applicationContext → ApplicationContext
The context that raised the event (the same object as source, typed).
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
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