SpringBoot学习(二)准备阶段~加载应用事件监听器

目录

使用

@Order(Ordered.LOWEST_PRECEDENCE)
public class FirstApplicationListener implements ApplicationListener<ContextRefreshedEvent> {
    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        System.out.println("FirstApplicationListener--");
    }
}
# Application Listeners
org.springframework.context.ApplicationListener=\
com.example.config.listener.FirstApplicationListener,\
com.example.config.listener.SecondApplicationListener

运行监听器

监听方法 对应事件 监听阶段 备注
starting ApplicationStartingEvent 应用刚启动
environmentPrepared ApplicationEnvironmentPreparedEvent
contextPrepared ApplicationContextInitializedEvent
contextLoaded ApplicationPreparedEvent
started ApplicationStartedEvent Spring Bean已完成初始化
running ApplicationReadyEvent
failed ApplicationFailedEvent

猜你喜欢

转载自www.cnblogs.com/VVII/p/12459558.html