Use of Applicationlistener

Source: Internet
Author: User

Today, when we look at Spring MVC source code, we find that the listener mechanism is used in the initialization process. So I'm going to learn the Applicationlistener.

Classes and interfaces designed to

  • Applicationevent
  • Applicationlistener
  • Applicationcontextaware

Below is a brief introduction to the use steps

  1. To customize a specevent inheritance applicationevent, an instance variable object source can hold the information that the time needs to be passed.
  2. Customize a Specapplicationcontextlistener implementation applicationlistener<specevent> interface, registered as a spring bean.
  3. Let the class that needs to publish specevent implement the Applicationcontextaware interface, so that with the ability to perceive ApplicationContext, spring will be responsible for injecting. When the event is published, the listener will be recalled.

The underlying phrase is to use the observer pattern. ApplicationContext is the subject, Applicationcontextlistener is the observer. The dependency of both is the Applicationcontextlistener interface.

Can be used to log log-out logs.

Use of Applicationlistener

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.