Spring Learning 8-spring Events

Source: Internet
Author: User


The events provided by spring are contextrefreshedevent,contextstartedevent,contextstoppedevent,contextclosedevent, Requesthandledevent


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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.