处理程序启动相关生命周期
需要在spring.factories中定义。
处理程序运行相关生命周期
可以使用@Component
配置。
泛型可限定接收事件类型
处理生命周期,用处不大
可以使用@Component
配置
- (系统)创建
ConfigurableBootstrapContext
- 创建
SpringApplicationRunListener
SpringApplicationRunListener#starting
SpringApplicationRunListener#environmentPrepared
- (系统)打印
Banner
SpringApplicationRunListener#contextPrepared
- (系统)关闭
ConfigurableBootstrapContext
SpringApplicationRunListener#contextLoaded
BeanFactoryPostProcessor
- (系统)初始化tomcat
- 初始化其他组件(其他框架、用户组件)
- 创建
ApplicationListener
ApplicationListener
接收事件ServletWebServerInitializedEvent
SmartLifecycle#start
ApplicationListener
接收事件ContextRefreshedEvent
ApplicationListener
接收事件ApplicationStartedEvent
ApplicationListener
接收事件AvailabilityChangeEvent
, state:CORRECT
SpringApplicationRunListener#started
- 执行
CommandLineRunner
ApplicationListener
接收事件ApplicationReadyEvent
ApplicationListener
接收事件AvailabilityChangeEvent
, state:ACCEPTING_TRAFFIC
SpringApplicationRunListener#ready
- (系统)
SpringApplication#run
方法结束 - ============================== 程序运行 ==============================
- (用户)发送http请求结束后:
ApplicationListener
接收事件ServletRequestHandledEvent
- (用户)发布自定义事件时:
ApplicationListener
接收事件 - ============================== 程序退出 ==============================
ApplicationListener
接收事件AvailabilityChangeEvent
, state:REFUSING_TRAFFIC
ApplicationListener
接收事件ContextClosedEvent
SmartLifecycle#stop
- 执行
DisposableBean#destroy