The event:
@Autowired
private ApplicationEventPublisher publisher;
send:
eventPublisher.publish(new CreateParticipantEvent(conversation, participant));
Do you send notifications to everyone? How does it work?
The event:
@Autowired
private ApplicationEventPublisher publisher;
send:
eventPublisher.publish(new CreateParticipantEvent(conversation, participant));
Do you send notifications to everyone? How does it work?
It allows you to publish events that can be received by
listeners
configured for it.You can use the events published by the framework or custom, to launch your own events you need 4 parts:
Setting
Declare the publisher in the web.xml so that it can publish events in the context of the application.
Event
Class to inherit from
ApplicationEvent
, in your caseCreateParticipantEvent
. For example:You can also use existing events, such as
HttpSessionDestroyedEvent
.publisher
The one in charge of "firing" those events, in this case the origin of your question. For example:
listening
The one in charge of listening to certain events. For example,
To use the existing ones, you simply have to create a
listener
for them.As additional information, here is a resource (in English) with a guide to good practices for publishing events.