Spring Boot(三)Application events and listeners

一、自定义监听器:

1、创建:

    META-INF/spring.factories

2、添加:

org.springframework.context.ApplicationListener=com.example.project.MyListener

二、应用程序事件发送顺序如下

Application events are sent in the following order, as your application runs:

1、An ApplicationStartedEvent is sent at the start of a run, but before any processing except the registration of listeners and initializers.


    ApplicationStartedEvent在任何处理之前,程序开始运行时被发送,初始化和自定义注册监听事件除外

2、An ApplicationEnvironmentPreparedEvent is sent when the Environment to be used in the context is known, but before the context is created.

    ApplicationEnvironmentPreparedEvent在上下文被创建之前,应用环境被已知的上下文环境中使用时被发送

3、An ApplicationPreparedEvent is sent just before the refresh is started, but after bean definitions have been loaded.

    ApplicationPreparedEvent在刷新开始之前,beans加载之后被发送

4、An ApplicationReadyEvent is sent after the refresh and any related callbacks have been processed to indicate the application is ready to service requests.

    ApplicationReadyEvent在刷新后被发送,并且任何相关的回调都已经被处理,表明该应用程序已经准备好处理服务请求

5、An ApplicationFailedEvent is sent if there is an exception on startup.

    ApplicationFailedEvent如果启动时存在异常时被发送

You often won’t need to use application events, but it can be handy to know that they exist. Internally, Spring Boot uses events to handle a variety of tasks.

我们不需要使用应用程序事件,但是很方便的知道他们存在,在SpringBoot内部使用各种事件来处理各种任务
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,179评论 19 139
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,169评论 6 342
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,568评论 25 709
  • 换了新的本子 这学期似乎很忙 但是总受放更多的精力在画上 成了一种瘾 沉迷于此 无法自止 并乐此不疲
    嗖嘎浅浅阅读 2,924评论 1 2
  • 我想试试麻将类做个麻将类的游戏。不多说,想到就开干。首先从别的例子中拷贝一套麻将资源,麻将的话一般是四个人玩,所以...
    樊开囧阅读 13,697评论 4 8

友情链接更多精彩内容