Explain the Events and listener in Spring framework?

Explain the Events and listener in Spring framework?

All the Events are the subclasses of abstract class org.springframework.context.ApplicationEvent. These are:
  * ContextClosedEvent :- Published when the application context is closed.
  * ContextRefereshedEvent :- Published when the application context is initialized or refereshed.
  * RequestHandledEvent :- Published within a web application context when a request is handled.

If you want a bean to respond to application events, all you need to do is implement the org.springframework.context.ApplicationListener interface. This interface forces your bean to implement the onApplicationEvent() method, which is responsible for reaching to the application event:
  
  public class RefreshListener implements ApplicaitonListener{
  public void onApplicationEvent(ApplicationEvent e) {
    some code here// 
}

You need to register it within the context:


By:Jalees
Date:2031-01-09 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related Spring sub Links

Spring sub interview questions and answers for experienced and fresher