Spring Boot 启动过程及 自定义 Listener等组件
一、启动过程
二、自定义组件
package com.example.jdbc.listener;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext; public class HelloApplicationContextInitiallizer implements ApplicationContextInitializer {
@Override
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
System.out.println("HelloApplicationContextInitiallizer.initialize");
}
}
package com.example.jdbc.listener; import org.springframework.boot.SpringApplicationRunListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment; public class HelloSpringApplicationRunListener implements SpringApplicationRunListener { @Override
public void environmentPrepared(ConfigurableEnvironment environment) {
System.out.println("HelloSpringApplicationRunListener...environmentPrepared...");
} @Override
public void contextPrepared(ConfigurableApplicationContext context) {
System.out.println("HelloSpringApplicationRunListener.contextPrepared");
} @Override
public void contextLoaded(ConfigurableApplicationContext context) {
System.out.println("HelloSpringApplicationRunListener.contextLoaded");
} @Override
public void started(ConfigurableApplicationContext context) {
System.out.println("HelloSpringApplicationRunListener.started");
} @Override
public void running(ConfigurableApplicationContext context) {
System.out.println("HelloSpringApplicationRunListener.running");
} @Override
public void failed(ConfigurableApplicationContext context, Throwable exception) {
System.out.println("HelloSpringApplicationRunListener.failed");
} @Override
public void starting() {
System.out.println("HelloSpringApplicationRunListener.starting");
}
}
/src/main/resources/META-INF/spring.factories
org.springframework.context.ApplicationContextInitializer=\
com.example.jdbc.listener.HelloApplicationContextInitiallizer org.springframework.context.ApplicationListener=\
com.example.jdbc.listener.HelloSpringApplicationRunListener
以上两个组件在项目启动过程中未能够成功执行,待解
以下两个组件成功加载并在项目启东时执行
package com.example.jdbc.listener; import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component; @Component
public class HelloApplicationRunner implements ApplicationRunner { @Override
public void run(ApplicationArguments args) throws Exception {
System.out.println("HelloApplicationRunner.run");
}
}
package com.example.jdbc.listener; import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import java.util.Arrays; @Component
public class HelloCommandLineRunner implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
System.out.println("HelloCommandLineRunner.run" + Arrays.asList(args));
}
}
Spring Boot 启动过程及 自定义 Listener等组件的更多相关文章
- Spring Boot启动过程及回调接口汇总
Spring Boot启动过程及回调接口汇总 链接: https://www.itcodemonkey.com/article/1431.html 来自:chanjarster (Daniel Qia ...
- Spring Boot启动过程(四):Spring Boot内嵌Tomcat启动
之前在Spring Boot启动过程(二)提到过createEmbeddedServletContainer创建了内嵌的Servlet容器,我用的是默认的Tomcat. private void cr ...
- Spring Boot启动过程(七):Connector初始化
Connector实例的创建已经在Spring Boot启动过程(四):Spring Boot内嵌Tomcat启动中提到了: Connector是LifecycleMBeanBase的子类,先是设置L ...
- Spring Boot启动过程(三)
我已经很精简了,两篇(Spring Boot启动过程(一).pring Boot启动过程(二))依然没写完,接着来. refreshContext之后的方法是afterRefresh,这名字起的真.. ...
- Spring Boot 启动过程
一切从SpringApplication.run()开始,最终返回一个ConfigurableApplicationContext 构造了一个SpringApplication对象,然后调用它的run ...
- Spring Boot启动过程(一)
之前在排查一个线上问题时,不得不仔细跑了很多遍Spring Boot的代码,于是整理一下,我用的是1.4.3.RELEASE. 首先,普通的入口,这没什么好说的,我就随便贴贴代码了: SpringAp ...
- Spring Boot启动过程(二)
书接上篇 该说refreshContext(context)了,首先是判断context是否是AbstractApplicationContext派生类的实例,之后调用了强转为AbstractAppl ...
- 转:Spring Boot启动过程
之前在排查一个线上问题时,不得不仔细跑了很多遍Spring Boot的代码,于是整理一下,我用的是1.4.3.RELEASE. 首先,普通的入口,这没什么好说的,我就随便贴贴代码了: SpringAp ...
- Spring boot 启动过程解析 logback
使用 Spring Boot 默认的日志框架 Logback. 所有这些 POM 依赖的好处在于为开发 Spring 应用提供了一个良好的基础.Spring Boot 所选择的第三方库是经过考虑的,是 ...
随机推荐
- 转《trackingjs人脸检测》
tracking.js是一个开源(BSD协议)的计算机视觉插件,在不同的浏览器中有不同的计算机视觉算法和技术,通过使用现代HTML5规范,能够实现实时颜色跟踪.人脸检测等功能,界面直观.核心文件轻量. ...
- loadrunner基础学习笔记二
virtual user generator(vugen) 在测试环境中,loadrunner在物理计算机上使用vuser代替实际用户.vuser以一种可重复.可预测的方式模拟典型用户的操作,对系统施 ...
- Linux系统——程序员跳槽必备
相信在看这篇文章的你,曾经或者现在是否跳槽呢,在北上广一线城市,你是否还在挣着那可怜巴巴的工资,过着拮据生活呢?但是自己想跳槽,却没有一技之长或者是自己的技术找工作太难了,那么我建议你学习下linux ...
- BZOJ4764弹飞大爷——LCT
题目描述 自从WC退役以来,大爷是越来越懒惰了.为了帮助他活动筋骨,也是受到了弹飞绵羊一题的启发,机房的小伙伴们 决定齐心合力构造一个下面这样的序列.这个序列共有N项,每项都代表了一个小伙伴的力量值, ...
- BZOJ3963 WF2011MachineWorks(动态规划+斜率优化+cdq分治)
按卖出时间排序后,设f[i]为买下第i台机器后的当前最大收益,则显然有f[i]=max{f[j]+gj*(di-dj-1)+rj-pi},且若此值<0,应设为-inf以表示无法购买第i台机器. ...
- 因为代理原因导致的NotSerializableException
错误信息: NotSerializableException Failed to serialize object Proxy 报这个错,一开始就往没有序列化这一块想,可是报错点是: excelT ...
- Web.config中设置启用webservice远程调试访问 参数看不到
<system.web><compilation debug="true" /> <!--begin启用webservice远程访问--> &l ...
- 洛谷CF868F Yet Another Minimization Problem(动态规划,决策单调性,分治)
洛谷题目传送门 貌似做所有的DP题都要先搞出暴力式子,再往正解上靠... 设\(f_{i,j}\)为前\(i\)个数分\(j\)段的最小花费,\(w_{l,r}\)为\([l,r]\)全在一段的费用. ...
- Deep Learning(深度学习)学习笔记整理系列二
声明: 1)该Deep Learning的学习系列是整理自网上很大牛和机器学习专家所无私奉献的资料的.具体引用的资料请看参考文献.具体的版本声明也参考原文献. 2)本文仅供学术交流,非商用.所以每一部 ...
- 【BZOJ1879】[SDOI2009]Bill的挑战(动态规划)
[BZOJ1879][SDOI2009]Bill的挑战(动态规划) 题面 BZOJ 洛谷 题解 本来还想着容斥来着,这个数据范围直接暴力就好.设\(f[i][S]\)表示当前填到了第\(i\)位,和\ ...