- ApplicationStartingEvent
- ApplicationEnvironmentPreparedEvent
- ApplicationContextInitializedEvent
- ApplicationPreparedEvent
- ApplicationStartedEvent
- ApplicationReadyEvent
- Create a class implementing ApplicationListener<SpringApplicationEvent> interface
public class ApplicationEventListener implements ApplicationListener<SpringApplicationEvent> {
@Overridepublic void onApplicationEvent(SpringApplicationEvent event) {
log.info( " > " + event );
}
}
- Register the above listener class to the spring boot application main class as
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {SpringApplication app = new SpringApplication(MyApplication .class);app.addListeners(new ApplicationEventListener());app.run(args);}
}
- Start the application and all the above events can be seen in the console logs.
No comments:
Post a Comment