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. 【RS】Local Collaborative Ranking - LCR: 局部协同排序

    [论文标题]Local Collaborative Ranking   (WWW '14 23rd WWW ) [论文作者]Joonseok [论文链接]Paper(11-pages // Doubl ...

  2. SpringBoot配置属性之Security

    SpringBoot配置属性系列 SpringBoot配置属性之MVC SpringBoot配置属性之Server SpringBoot配置属性之DataSource SpringBoot配置属性之N ...

  3. jquery 父、子页面之间页面元素的获取,方法的调用

    一.jquery 父.子页面之间页面元素的获取,方法的调用: 1. 父页面获取子页面元素: 格式:$("#iframe的ID").contents().find("#if ...

  4. NSAttributedString 上下标---!!!!!

    下面这段,亲试可用 /*将符号转换为上标*/ -(NSMutableAttributedString *)changeToSuperscriptForNumberSignWith:(NSString ...

  5. 【webservice】使用命令wsimport构建WebService客户端

    wsimport命令介绍 在JDK的bin文件夹中,有一个wsimport.exe,这个工具依据wsdl文件生成相应的类文件,然后用这些类文件,就可以像调用本地的类一样调用WebService提供的方 ...

  6. response.encodeURL的用法

    Java Servlet API 中引用 Session 机制来追踪客户的状态.Servlet API 中定义了 javax.servlet.http.HttpSession 接口,Servlet 容 ...

  7. Linux软中断、tasklet和工作队列

    Linux内核中的软中断.tasklet和工作队列详解 引言 软中断.tasklet和工作队列并不是Linux内核中一直存在的机制,而是由更早版本的内核中的“下半部”(bottom half)演变而来 ...

  8. python packages prebuild for windows

    python  prebuild / precompiled packages for windows  by uci edu   在python windows环境下作业,有时候会碰上一些无厘头的问 ...

  9. pip安装包时遇到的Bug

    [背景] 今天打包人生中的第一个package到PyPi,在linux上执行pip3 install mysqltools-python安装一点问题都没有,打脸的是在自己的MAC上 居然安装不上 pi ...

  10. js日期操作,某天的N天后,一个月后的日期

    var date = new Date(); var tomorrow = date.setDate(new Date().getDate() + 10); //10天后的日期 console.log ...