1:applicationevent
The events provided by spring are contextrefreshedevent,contextstartedevent,contextstoppedevent,contextclosedevent, Requesthandledevent
Wait
Custom event: Inherits the Applicationevent class, for example,
public class Blacklistevent extends Applicationevent {
private final String address;
Private final String test;
Public Blacklistevent (Object source, string address, string test) {
super (source);
this.address = address;
this.test = test;
}
Accessor and other methods ...
2: Publish an event, Applicationeventpublisher the Publishevent method,
Specifically, the bean that is usually defined
Implement the Applicationeventpublisheraware interface to get the instance, and then you can publish the event
3: Register for listening: The bean that implements the Applicationlistener interface is invoked by the container, activating event handling
4: Add a little Spring event the default processing method is synchronous, that is, Applicationeventpublisher releases an event that blocks until all listener are executed.
If you want to use other processing methods, refer to the Javadoc for spring's applicationeventmulticaster.