Listen Spring built-in context related events by implementing ApplicationListener
Example code:
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Bean
AListenerBean listenerBean() {
return new AListenerBean();
}
private static class AListenerBean implements ApplicationListener<ContextRefreshedEvent> {
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
System.out.println("[Shark] context refreshed event received: " + event);
}
}
}