SpringBoot应用启动过程挂载点与Spring事件监听对应如下表:
starting ApplicationStartingEvent environmentPrepared ApplicationEnvironmentPreparedEvent contextPrepared ApplicationContextInitializedEvent contextLoaded ApplicationPreparedEvent started ApplicationStartedEvent running ApplicationReadyEvent failed ApplicationFailedEvent
Spring中注册监听事件:
@Component public class AppListener implements ApplicationListener<ApplicationReadyEvent> { @Override public void onApplicationEvent(ApplicationReadyEvent event) { System.out.println("SPRING BOOT READY!!!"); } }