Spring Boot(三)Application events and listeners

简介: 一、自定义监听器:1、创建: META-INF/spring.factories2、添加: org.springframework.context.ApplicationListener=com.

一、自定义监听器:

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内部使用各种事件来处理各种任务
目录
相关文章
|
5月前
|
缓存 Java Maven
Spring Boot 启动错误:To display the conditions report re-run your application with ‘debug‘ enable —【已解决】
Spring Boot 启动错误:To display the conditions report re-run your application with ‘debug‘ enable —【已解决】
919 1
|
4月前
|
Java Spring
Spring Boot Application in default package
Spring Boot Application in default package
|
Java Spring
Command line is too long. Shorten command line for Application or also for Spring Boot default confi
Command line is too long. Shorten command line for Application or also for Spring Boot default confi
41 1
|
6月前
|
Java Linux Windows
windows解决SpringBoot启动时:APPLICATION FAILED TO START
windows解决SpringBoot启动时:APPLICATION FAILED TO START
313 0
|
Java
【异常】SpringBoot报错Command line is too long.Shorten command line for Application or also for Applicatio
【异常】SpringBoot报错Command line is too long.Shorten command line for Application or also for Applicatio
654 0
|
Java Linux Spring
每日一博 - Spring Boot Application as a Service
每日一博 - Spring Boot Application as a Service
97 0
|
前端开发 Java Spring
Spring MVC框架:第四章:属性域使用(request域、session域、application域)
Spring MVC框架:第四章:属性域使用(request域、session域、application域)
125 0
Spring MVC框架:第四章:属性域使用(request域、session域、application域)
|
Java 应用服务中间件 Spring
SpringBoot Application事件监听的实现方案(动态写入yml)
SpringBoot Application事件监听的实现方案(动态写入yml)
SpringBoot Application事件监听的实现方案(动态写入yml)
|
Java
SpringBoot配置文件application
SpringBoot配置文件application
96 2
springboot配置文件application没有生效处理方式
springboot application.properties不生效(没有生效就是那个文件不是叶子的形态的玩意)
下一篇
无影云桌面