一、启动过程


二、自定义组件


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. Python文件os模块

    一.文件操作 1.打开一个文件 fo = open("foo.txt", "wb") fo.write( "www.runoob.com!\nVery ...

  2. linux bin & sbin different

    linux bin & sbin different flutter & $PATH http://blog.taylormcgann.com/2014/04/11/differenc ...

  3. python之导入模块

    导入模块的方法: 导入整个模块:import module_name 导入特定函数:from module_name import function_name 给函数指定别名:from module_ ...

  4. python之Map函数

    # map()函数使用举例 # 功能:map()接受一个函数f和一个或多个list,将f依次作用在list的每个元素,得到一个新的列表 # 语法:map(方法名,列表,[列表2]) # 注意:map( ...

  5. 查看本地Git仓库历史修改内容

    查看历史内容 在.git文件 同级目录下,右键 选择 git history 但是红框中的路径无法拷贝.右键红框中的任一文件,有 HighLight this only, Highlight this ...

  6. 架构师成长之路7.1 CDN理论

    点击返回架构师成长之路 架构师成长之路7.1 CDN理论 CDN,Content Distribute Network,内容分发网络:CDN解决的是如何将数据快速可靠从源站传递到用户的问题.用户获取数 ...

  7. python2和python3的主要区别

    作为一个py3土著,并不是很关心这个问题,但是总有人隔三差五问这个问题,还是捋了一下. 这里列出几个主要区别: 1.最常见的人尽皆知的print()函数 在py2中,print是一个语句,不带括号,也 ...

  8. 隐藏技能go:linkname

    来源:https://blog.csdn.net/lastsweetop/article/details/78830772 什么是go:linkname 指令的格式如下: //go:linkname ...

  9. 使用fiddler模拟http请求

    概述  与httpwath相比,fiddler能模拟http请求.能断点调试.http分析统计吸引了我,使用之后感觉这个工具非常不错,这篇文章只单介绍一下fiddler工作原理,简单介绍一下它的重要功 ...

  10. ASP 运行结果显示空白 --- 是编码的原因。

    比如有一个 a.asp 文件编码: utf-8 在a.asp代码中有一行:<!--#include file="b.asp"--> 但是 b.asp 文件编码是 gb2 ...