一、启动过程


二、自定义组件


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等组件的更多相关文章

  1. Spring Boot启动过程及回调接口汇总

    Spring Boot启动过程及回调接口汇总 链接: https://www.itcodemonkey.com/article/1431.html 来自:chanjarster (Daniel Qia ...

  2. Spring Boot启动过程(四):Spring Boot内嵌Tomcat启动

    之前在Spring Boot启动过程(二)提到过createEmbeddedServletContainer创建了内嵌的Servlet容器,我用的是默认的Tomcat. private void cr ...

  3. Spring Boot启动过程(七):Connector初始化

    Connector实例的创建已经在Spring Boot启动过程(四):Spring Boot内嵌Tomcat启动中提到了: Connector是LifecycleMBeanBase的子类,先是设置L ...

  4. Spring Boot启动过程(三)

    我已经很精简了,两篇(Spring Boot启动过程(一).pring Boot启动过程(二))依然没写完,接着来. refreshContext之后的方法是afterRefresh,这名字起的真.. ...

  5. Spring Boot 启动过程

    一切从SpringApplication.run()开始,最终返回一个ConfigurableApplicationContext 构造了一个SpringApplication对象,然后调用它的run ...

  6. Spring Boot启动过程(一)

    之前在排查一个线上问题时,不得不仔细跑了很多遍Spring Boot的代码,于是整理一下,我用的是1.4.3.RELEASE. 首先,普通的入口,这没什么好说的,我就随便贴贴代码了: SpringAp ...

  7. Spring Boot启动过程(二)

    书接上篇 该说refreshContext(context)了,首先是判断context是否是AbstractApplicationContext派生类的实例,之后调用了强转为AbstractAppl ...

  8. 转:Spring Boot启动过程

    之前在排查一个线上问题时,不得不仔细跑了很多遍Spring Boot的代码,于是整理一下,我用的是1.4.3.RELEASE. 首先,普通的入口,这没什么好说的,我就随便贴贴代码了: SpringAp ...

  9. Spring boot 启动过程解析 logback

    使用 Spring Boot 默认的日志框架 Logback. 所有这些 POM 依赖的好处在于为开发 Spring 应用提供了一个良好的基础.Spring Boot 所选择的第三方库是经过考虑的,是 ...

随机推荐

  1. msyql sql语句收集

    在不断的学习中,发现了一些新的slq语句,总结于此. 一.复制数据表的sql 1)create table tableName  as  select  * from   tableName2     ...

  2. Linux常用指令-ssh

    目录 ssh远程登陆 ssh免密码登陆 生成公钥和私钥 将公钥复制到其他从机 文件说明 id_rsa id_rsa.pub authorized_keys known_host SSH(远程连接工具) ...

  3. mysql问题处理积累

    1.mysql errors:message from server: "Host 'xxx' is blocked because of many connection errors; u ...

  4. Flutter & Dart

    Flutter & Dart https://www.dartlang.org/install https://flutter.dev/ https://flutter.dev/docs/ge ...

  5. php技术–php中感叹号!和双感叹号!!的用法(三元运算)

    ---恢复内容开始--- if(文章==有用){狂点我;} 在php持术或其他语言中我们经常会看到感叹号的用法,有一定程序语言基础的朋友都知道单个感叹号的作用是取反的意思,也就是取当前结果的反面,如: ...

  6. Docker容器从一知半解到入门

    Docker是一个开源的.跨平台的应用容器引擎,可以让技术开发认用打包他们的应用以及一些依赖包到一个可移植的容器平台中,发布到任何流行的Linux操作系统上面,也可以在Windows和mac操作系统上 ...

  7. Google社交梦之隐私问题

    导读 2011年6月底,Google+ 作为Facebook最有力狙击者的身份诞生,同时以隐私功能作为两者主要区分点:2018年10月,Google+被曝发生重大隐私泄露问题,消费版本被宣布仅剩10个 ...

  8. MT【18】幂平均不等式的证明

    评:证明时对求导要求较高,利用这个观点,对平时熟悉的调和平均,几何平均,算术平均,平方平均有了更深 刻的认识.

  9. AtCoder Grand Contest 011

    AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...

  10. [hdu3966]Aragorn's Story

    传送门 题目描述 Our protagonist is the handsome human prince Aragorn comes from The Lord of the Rings. One ...