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. 实现外卖选餐时两级 tableView 联动效果

    最近实现了下饿了么中选餐时两级tableView联动效果,先上效果图,大家感受一下: 下面说下具体实现步骤: 首先分解一下,实现这个需求主要是两点,一是点击左边tableView,同时滚动右边tabl ...

  2. linux下串口工具minicom

    系统环境:ubuntu  14 .04  和ubuntu 16.04 我当时的需要主要是两个,能够看到正常串口输出,并且把串口内容实时输出到文件中 那接下来工作主要是两个:1.安装 2.配置 相信各位 ...

  3. Ubuntu菜鸟入门(十六)—— 安装视频播放器vlc

    sudo add-apt-repository ppa:videolan/master-daily sudo apt-get update sudo apt-get install vlc Ubunt ...

  4. jquery ajax 回调函数的值alert出来[object Object] 解决方法

    $("#activity_project").change(function(){ var pro=$("#activity_project").val(); ...

  5. ToString()的各种用法(大全) C# 获取所有国家时间格式

    ToString()的各种用法(大全)   常用例子: string str = ""; str = 123456.ToString("N"); //生成 12 ...

  6. MVC+Spring.NET+NHibernate .NET SSH框架整合 C# 委托异步 和 async /await 两种实现的异步 如何消除点击按钮时周围出现的白线? Linq中 AsQueryable(), AsEnumerable()和ToList()的区别和用法

    MVC+Spring.NET+NHibernate .NET SSH框架整合   在JAVA中,SSH框架可谓是无人不晓,就和.NET中的MVC框架一样普及.作为一个初学者,可以感受到.NET出了MV ...

  7. Android基础之——CountDownTimer类,轻松实现倒计时功能

    在发现这个类之前,一直是用的handler,子线程发消息,UI线程进行倒计时的显示工作.前几天在做一个倒计时显示的时候发现了这个类,用起来非常方便 翻看了下源代码.内部已经帮我们实现了handler的 ...

  8. Matlab的集合运算[转]

    今天遇到一个问题:有向量a和向量b,b是a的子向量(元素全部来自a),求向量a去掉向量b后剩下的元素构成的向量. 这么一个简单的问题,搜了半天也没有得到结果,因为找不到合适的关键词来描述这个问题. 在 ...

  9. HTML常用模板:用DIV实现网站首页、后台管理首页(整理)

    1. 说明 网上下载的模板,用DIV实现页面模块之间的分隔(不是用frameset/frame).可以选择有无header/menu/footer,主体如何等等.删除了几个我认为重复的.重新命名而已. ...

  10. Bash - 趣味Shell

    好消息:本人博客已开通.很多其它博客请进 http://swplzj.github.io 今天抽闲玩了一下Shell.发现几个比較有意思的.记录一下. 终端彩虹字:lolcat 图形化文字:figle ...