https://www.cnblogs.com/fdzfd/p/7872909.html

*****************************************************

一:Application 事件

(1)ApplicationStartingEvent

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

(2)ApplicationEnvironmentPreparedEvent

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

示例:

public class MyListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {

    @Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
SpringApplication app = event.getSpringApplication();
// app.setBannerMode(Banner.Mode.OFF);
System.out.println("#####MyListener found!#####");
}
}

Application类中添加

@SpringBootApplication
public class Application {
public static void main(String[] args){
SpringApplication app = new SpringApplication(Application.class);
app.addListeners(new MyListener());
app.run(args);
}
}

运行结果:

(3)ApplicationPreparedEvent

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

(4)ApplicationReadyEvent

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

当Application启动好后调用

示例:

public class MyListener implements ApplicationListener<ApplicationReadyEvent> {

    @Override
public void onApplicationEvent(ApplicationReadyEvent event) {
System.out.println("#####MyListener found!#####");
}
}

运行结果位置:

(5)ApplicationFailedEvent

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

这里举了两种事件的例子,其他3种事件可以通过改写MyListener中参数调试。

Spring Boot Application 事件和监听器的更多相关文章

  1. Spring Boot 启动事件和监听器,太强大了!

    大家都知道,在 Spring 框架中事件和监听无处不在,打通了 Spring 框架的任督二脉,事件和监听也是 Spring 框架必学的核心知识之一. 一般来说,我们很少会使用到应用程序事件,但我们也不 ...

  2. Spring Boot实践——事件监听

    借鉴:https://blog.csdn.net/Harry_ZH_Wang/article/details/79691994 https://blog.csdn.net/ignorewho/arti ...

  3. 【转】spring boot application.properties 配置参数详情

    multipart multipart.enabled 开启上传支持(默认:true) multipart.file-size-threshold: 大于该值的文件会被写到磁盘上 multipart. ...

  4. Inspection info: Checks Spring Boot application .properties configuration files. Highlights unresolved and deprecated configuration keys and in

    Cannot resolve class or package ‘jdbc’ less… (Ctrl+F1) Inspection info: Checks Spring Boot applicati ...

  5. SpringBoot零XML配置的Spring Boot Application

    Spring Boot 提供了一种统一的方式来管理应用的配置,允许开发人员使用属性properties文件.YAML 文件.环境变量和命令行参数来定义优先级不同的配置值.零XML配置的Spring B ...

  6. Spring boot application.properties 配置

    原文链接: http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.ht ...

  7. Spring Boot Application

    spring boot默认已经配置了很多环境变量,例如,tomcat的默认端口是8080,项目的contextpath是“/”等等,spring boot允许你自定义一个application.pro ...

  8. spring boot application.properties 属性详解

    2019年3月21日17:09:59 英文原版: https://docs.spring.io/spring-boot/docs/current/reference/html/common-appli ...

  9. spring boot application properties配置详解

    # =================================================================== # COMMON SPRING BOOT PROPERTIE ...

随机推荐

  1. Ubuntu创建新用户并增加管理员权限(授权有问题)

    转自:Ubuntu创建新用户并增加管理员权限 $是普通管员,#是系统管理员,在Ubuntu下,root用户默认是没有密码的,因此也就无法使用(据说是为了安全).想用root的话,得给root用户设置一 ...

  2. 每日学习与工作计划移至日事清APP

    今天今天开始,每日学习与工作计划移至日事清APP. 博客园依然是我写文字的主战场.日事清APP仅限于做计划.

  3. java.lang.IllegalStateException: Failed to load ApplicationContext selenium 异常 解决

    WARN <init>, HHH000409: Using org.hibernate.id.UUIDHexGenerator which does not generate IETF R ...

  4. NSObject协议中方法:description 和 debugDescription

    description基本概念 1.NSLog(@"%@", objectA);这会自动调用objectA的description方法来输出ObjectA的描述信息. 2.desc ...

  5. syslog远程日志存储/514端口【转】

    昨天在抓包的时候,发现在514端口,有SYSLOG字段的东西,不知道是用来干啥的,现在来分析一下: 其实他是在电脑间用了syslog远程日志存储,他用udp监控了514端口的数据流,之后收集整理日志: ...

  6. Nginx+FastCGI运行原理(二)

    1.4 PHP与PHP-FPM的安装及优化(2) 标签rlimit_files用于设置PHP-FPM对打开文件描述符的限制,默认值为1024.这个标签的值必须和Linux内核打开文件数关联起来,例如, ...

  7. rc522头文件

    //本头文件是以51为蓝本 #ifndef __rc522_h__ #define __rc522_h__ #include <string.h> #include <wiringP ...

  8. 【JQuery】jQuery(document).ready(function($) { });的几种表示方法及load和ready的区别

    jQuery中处理加载时机的几种方式 第一种: jQuery(document).ready(function() { alert("你好"); }); //或 $(documen ...

  9. OpenCV 学习笔记03 drawContours函数

    opencv-python   4.0.1 轮廓的绘制或填充. cv2.drawContours(image, contours, contourIdx, color[, thickness[, li ...

  10. Innodb中自增长值的列

    Innodb中,自增长值的列必须是索引,同时必须是索引的第一个列.如果不是第一个列,数据库会报出异常 mysql> create table t_inc01( -> a int auto_ ...