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
- To customize a specevent inheritance applicationevent, an instance variable object source can hold the information that the time needs to be passed.
- Customize a Specapplicationcontextlistener implementation applicationlistener<specevent> interface, registered as a spring bean.
- 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