Spring Boot Application 事件和监听器
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 事件和监听器的更多相关文章
- Spring Boot 启动事件和监听器,太强大了!
大家都知道,在 Spring 框架中事件和监听无处不在,打通了 Spring 框架的任督二脉,事件和监听也是 Spring 框架必学的核心知识之一. 一般来说,我们很少会使用到应用程序事件,但我们也不 ...
- Spring Boot实践——事件监听
借鉴:https://blog.csdn.net/Harry_ZH_Wang/article/details/79691994 https://blog.csdn.net/ignorewho/arti ...
- 【转】spring boot application.properties 配置参数详情
multipart multipart.enabled 开启上传支持(默认:true) multipart.file-size-threshold: 大于该值的文件会被写到磁盘上 multipart. ...
- 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 ...
- SpringBoot零XML配置的Spring Boot Application
Spring Boot 提供了一种统一的方式来管理应用的配置,允许开发人员使用属性properties文件.YAML 文件.环境变量和命令行参数来定义优先级不同的配置值.零XML配置的Spring B ...
- Spring boot application.properties 配置
原文链接: http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.ht ...
- Spring Boot Application
spring boot默认已经配置了很多环境变量,例如,tomcat的默认端口是8080,项目的contextpath是“/”等等,spring boot允许你自定义一个application.pro ...
- spring boot application.properties 属性详解
2019年3月21日17:09:59 英文原版: https://docs.spring.io/spring-boot/docs/current/reference/html/common-appli ...
- spring boot application properties配置详解
# =================================================================== # COMMON SPRING BOOT PROPERTIE ...
随机推荐
- Mysql模糊查询 select count(*) from sys_invitation where from_id like '%1006%';
select count(*) from sys_invitation where from_id like '%1006%'; 查询结果 select * from sys_invitation w ...
- 百度地图 ijintui以及七牛、百度编辑器、kindeditor
密码是明文存储的 sig错误是因为params没拼接上md5后的秘钥,测试时候可以在 Api\Controller\CommonController\_initialize 方法里注释掉效验的代码 代 ...
- 树莓派进阶之路 (026) - 基于 Samba 实现 NAS 系统
摆弄了几天Raspberry Pi,在搞定了无线网络.FTP服务之后,打算更进一步,通过Samba实现NAS系统与PC共享文件.需要安装的软件:sudo apt-get install samba s ...
- CentOS 开启防火墙 firewall ,mysql 远程访问
最近在阿里云服务器centos上安装了mysql数据库,默认是不开启远端访问功能,需要设置一下防火墙,在开放默认端口号 3306时提示FirewallD is not running,经过排查发现是防 ...
- appium简明教程(8)——那些工具
那片笑声让我想起我的那些tool 在我生命每个角落静静为我开着 我曾以为我会永远守在她身旁 今天我们已经离去在人海茫茫 她们都老了吧 都更新换代了吧 幸运的是我曾陪她们开发 啦…… 想她 啦…… 她还 ...
- javascript 中的==(相等运算符)与===(等同运算符)比较
javascript 中的==(相等运算符)与===(等同运算符)比较:(1)==用于一般比较,===用于严格比较,(2)==在比较的时候可以转换数据类型,===严格比较,只要类型不匹配就返回flas ...
- 【转载】使用 Google Guava 美化你的 Java 代码
转载地址: https://blog.csdn.net/wisgood/article/details/13297535 原文地址:https://my.oschina.net/leejun2005/ ...
- 温故而知新 Ajax 的新坑 dataType: 'json'
为了方便实验,我随便捏造了一个json数据,然后放在php中输出. 请求明明是200,json数据也正确,但ajax就是不执行success回调? 原因是 dataType: 'json', 导致的. ...
- WEB服务器搭建–IIS
功能作用 IIS是一个World Wide Web server.Gopher server和FTP server全部包容在里面. IIS意味着你能发布网页,并且有ASP(Active Server ...
- hive splict, explode, lateral view, concat_ws
hive> create table arrays (x array<string>) > row format delimited fields terminated by ...