gpt4 book ai didi

spring boot之SpringApplication 事件监听

转载 作者:qq735679552 更新时间:2022-09-29 22:32:09 25 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章spring boot之SpringApplication 事件监听由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

spring application listener 。

在 spring 框架中,有多种事件, 这些时间会在不同的运行时刻发布,来通知监听者。本文仅仅介绍 SpringApplicationEvent 的事件的监听.

事件类型 。

  。

EventType 发布时间
ApplicationContextInitializedEvent 在 SpringApplication正在启动, ApplicationContext 已经准备好了,ApplicationContextInitializers 被调用, bean definitions 被加载之前
ApplicationStartingEvent 在一次启动之前发布
ApplicationEnvironmentPreparedEvent 在 Environment 准备好之后,会有 context 去使用这一 Environment, 会在 context 创建之前发出
ApplicationPreparedEvent 会在 bean definitions 加载之后,refresh 之前发布
ApplicationStartedEvent context 更新之后,任何应用或命令行启动调用之前
ApplicationReadyEvent 任何应用或命令行启动调用之后发布,说明应用已经可以被请求了
ApplicationFailedEvent 启动发生有异常时发步

  。

如何监听 。

监听器需要使用 org.springframework.context.ApplicationListener 这个接口的实例, 其声明如下:

@FunctionalInterfacepublic interface ApplicationListener<E extends ApplicationEvent> extends EventListener {  /**  * Handle an application event. * @param event the event to respond to  */  void onApplicationEvent(E event);}

需要使用 SpringApplication.addListeners(… 。

最后此篇关于spring boot之SpringApplication 事件监听的文章就讲到这里了,如果你想了解更多关于spring boot之SpringApplication 事件监听的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com