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. hibernate实现多表联合查询

    转自:http://blog.sina.com.cn/s/blog_67b9ad8d01010by1.html 以前用sql实现联合查询 是非常简单的事,只需要写sql语句就可以,第一次遇到hiber ...

  2. hihocoder第233周

    题目链接 题目描述 给定一个数组a[N],N小于1e5.把数组划分成若干个片段,每个片段的和都不为0,问有多少种划分方法? 方法描述 定义f(i)表示0~i共有多少种划分方式,则$f(j)=\sum_ ...

  3. 【Android】Android如何实现手机震动

    实现手机震动其实很简单,手机震动使用是Vibrator类,然后震动也是需要权限的,在使用之前在AndroidManifest.xml文件中添加 <uses-permission android: ...

  4. Git 配置(分布式版本控制系统)

    1.Mac Git 配置文件 既然已经在系统上安装了 Git,你会想要做几件事来定制你的 Git 环境.每台计算机上只需要配置一次,程序升级时会保留配置信息.你可以在任何时候再次通过运行命令来修改它们 ...

  5. 【struts2】自定义登录检查拦截器

    在实际开发中,一个常见的功能要求是:有很多操作都需要登录后才能操作,如果操作的时候还没有登录,那么通常情况下会要求跳转回到登录页面. 1)如何实现这样的功能呢? 在具体实现之前,先来考虑几个问题: ( ...

  6. SmartUpload类实现上传和下载

    实现文件的上传与下载,可以使用Java的I/O流的类来实现,也可以使用专业的上传.下载组件.这些组件提供了现成的类,程序员只需调用这些类中的方法即可实现文件的上传与下载.本章将向读者介绍如何应用jsp ...

  7. Intent----android中的伟大邮差

    在android中,intent就像是一个邮差,辛勤高效的在各个组件之间来回穿梭.我们可以通过它启动一个Activity或者Service,或者是发送给广播组件,又或者是与后台的Service进行通信 ...

  8. Axure谷歌浏览器Chrome扩展程序下载及安装方法

    对于很多需要设计产品原型的朋友来说,Axure RP Pro可谓是非常方便.好用的一款软件,因为它不仅能绘制出详细的产品构思,也能生成浏览器格式的产品原型.但是如果想把原型拿给客户查看,千万记得给浏览 ...

  9. c#asp.net url 传递中文参数要使用 System.Web.HttpUtility.UrlEncode 而不能使用Server.UrlEncode

    最近网站里的参数包括中文的例如: http://www.taiba/Tag%b0%ae%c7%e9.html 已开始使用 Server.UrlEncode来做的,但发现,有一些中文在url重写的是说找 ...

  10. []如何在Windows 10中更改文件夹背景颜色

    ini文件.我们甚至可以使用相同的技术将图片设置为文件夹背景. 已有工具可以更改Windows 7中Windows资源管理器背景的颜色,并将图像设置为Windows 7中的文件夹背景,但这些工具与Wi ...