Sends an event to every listener interested in it.
Inject it into a bean that wants to tell the rest of the application
that something happened (an order placed, a user signed in) without
calling the interested beans itself. Listeners are @EventListener
methods and listener beans; the publisher does not know them. Every
application context is a publisher, and the context registers itself
as the bean injected for this type.
Any object can be an event. One that is not an ApplicationEvent is
wrapped in a PayloadApplicationEvent<T> of its static type T, and
listeners of T receive the object itself.
// The service announces each order; shipping and mailing listen.
@Service()
class OrderService {
OrderService(this.publisher);
final ApplicationEventPublisher publisher;
void place(int id, int total) =>
publisher.publishEvent(OrderPlaced(id, total));
}
Spring (Java):
@Service
class OrderService {
OrderService(ApplicationEventPublisher publisher) { ... }
void place(int id, int total) {
publisher.publishEvent(new OrderPlaced(id, total));
}
}
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
publishEvent<
T extends Object> (T event) → void -
Delivers
eventto every listener that accepts it. By default the listeners run before this call returns, and a listener error reaches the caller; with an asynchronous multicaster they run later. Aneventthat is not anApplicationEventis wrapped in aPayloadApplicationEvent<T>. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited