SpringApplication:
private void initialize(Object[] sources) {
if (sources != null && sources.length > 0) {
this.sources.addAll(Arrays.asList(sources));
}
this.webEnvironment = deduceWebEnvironment();
// 从spring.factories里读取所有 ApplicationContextInitializer,并记入 SpringApplication
setInitializers((Collection) getSpringFactoriesInstances(
ApplicationContextInitializer.class));
// 从spring.factories里读取所有 ApplicationListener,并记入 SpringApplication
setListeners((Collection) getSpringFactoriesInstances(ApplicationListener.class));
this.mainApplicationClass = deduceMainApplicationClass();
}
public ConfigurableApplicationContext run(String... args) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
ConfigurableApplicationContext context = null;
FailureAnalyzers analyzers = null;
configureHeadlessProperty();
// 从spring.factories里读取所有 SpringApplicationRunListener,监听springboot启动,参考:org.springframework.boot.context.event.EventPublishingRunListener
SpringApplicationRunListeners listeners = getRunListeners(args);
listeners.starting();
try {
ApplicationArguments applicationArguments = new DefaultApplicationArguments(
args);
ConfigurableEnvironment environment = prepareEnvironment(listeners,
applicationArguments);
Banner printedBanner = printBanner(environment);
// web环境下默认的 ApplicationContext: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext
// 非web环境下默认的 ApplicationContext: org.springframework.context.annotation.AnnotationConfigApplicationContext
context = createApplicationContext();
analyzers = new FailureAnalyzers(context);
// org.springframework.cloud.bootstrap.config.PropertySourceBootstrapProperties 会通过 ApplicationContextInitializer,准备 PropertySource
// PropertySourceBootstrapProperties 收集 PropertySourceLocator 来获得PropertySource
// 其中 org.springframework.cloud.config.client.ConfigServicePropertySourceLocator 是 Cloud Config Client 提供的 PropertySourceLocator
prepareContext(context, environment, listeners, applicationArguments,
printedBanner);
// 调用 context.refresh
refreshContext(context);
afterRefresh(context, applicationArguments);
listeners.finished(context, null);
stopWatch.stop();
if (this.logStartupInfo) {
new StartupInfoLogger(this.mainApplicationClass)
.logStarted(getApplicationLog(), stopWatch);
}
return context;
}
catch (Throwable ex) {
handleRunFailure(context, listeners, analyzers, ex);
throw new IllegalStateException(ex);
}
}

SpringApplication初始化的更多相关文章

  1. SpringBoot启动流程分析(一):SpringApplication类初始化过程

    SpringBoot系列文章简介 SpringBoot源码阅读辅助篇: Spring IoC容器与应用上下文的设计与实现 SpringBoot启动流程源码分析: SpringBoot启动流程分析(一) ...

  2. springboot源码解析 - 构建SpringApplication

    1 package com.microservice.framework; 2 3 import org.springframework.boot.SpringApplication; 4 impor ...

  3. Spring Boot 2.0系列文章(七):SpringApplication 深入探索

    关注我 转载请务必注明原创地址为:http://www.54tianzhisheng.cn/2018/04/30/springboot_SpringApplication/ 前言 在 Spring B ...

  4. Spring Boot 启动(一) SpringApplication 分析

    Spring Boot 启动(一) SpringApplication 分析 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html ...

  5. 【附3】springboot源码解析 - 构建SpringApplication

    package com.microservice.framework; import org.springframework.boot.SpringApplication; import org.sp ...

  6. 附3 springboot源码解析 - 构建SpringApplication

    package com.microservice.framework; import org.springframework.boot.SpringApplication; import org.sp ...

  7. SpringBoot SpringApplication底层源码分析与自动装配

    目录 抛出问题 @SpringBootApplication注解剖析 SpringApplication类剖析 第一步:配置SpringBoot Bean来源 第二步 :自动推断SpringBoot的 ...

  8. SpringBoot源码分析之---SpringBoot项目启动类SpringApplication浅析

    源码版本说明 本文源码采用版本为SpringBoot 2.1.0BUILD,对应的SpringFramework 5.1.0.RC1 注意:本文只是从整体上梳理流程,不做具体深入分析 SpringBo ...

  9. SpringBoot源码修炼—系统初始化器

    SpringBoot源码修炼-系统初始化器 传统SSM框架与SpringBoot框架简要对比 SSM搭建流程 缺点: 耗时长 配置文件繁琐 需要找合适版本的jar包 SpringBoot搭建流程 优点 ...

随机推荐

  1. C++ 第四课:ASCII 码表

    下面的 ASCII 码表包含数值在0-127之间的字符的十进制.八进制以及十六进制表示. 十进制 八进制 十六进制 字符 描述 0 0 00 NUL   1 1 01 SOH start of hea ...

  2. WIN下Git GUI 教程

    现在很多都有git来托管项目或者来查找资料,但是看起来操作不是很方便,现在由于win下可以直接使用git gui,让使用git变得方便,当然这只是针对日常简单的使用,如果想详细的使用,可以去参考廖学峰 ...

  3. MySQL事物系列:3:innodb_flush_log_at_trx_commit小实验

    1:创建表和存储过程 mysql> create database trx; Query OK, 1 row affected (0.02 sec) mysql> USE trx Data ...

  4. SpringBoot使用JSP渲染页面

    1.pom.xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId& ...

  5. Oracle官方文档

    Oracle DBA 10g 两日速成课程 http://www.oracle.com/webfolder/technetwork/cn/tutorials/obe/db/10g/r2/2day_db ...

  6. 实现一个简单的shared_ptr

    翻看以前的代码的时候发现一个shared_ptr的简单实现. 我记得是网上的一篇例子(好像改了一点),但是又懒得找出处了 ╮(╯▽╰)╭. 觉得这份代码足以用来初步了解shared_ptr的实现了. ...

  7. 要想找出包含“w”的名字

    要想找出包含“w”的名字:mysql> SELECT * FROM pet WHERE name LIKE '%w%'“_”:匹配任何单个字符“%”:匹配任意数目字符(包括零字符)

  8. [转载]ubuntu防火墙设置

    原文地址:ubuntu防火墙设置作者:風飏    自打2.4版本以后的Linux内核中, 提供了一个非常优秀的防火墙工具.这个工具可以对出入服务的网络数据进行分割.过滤.转发等等细微的控制,进而实现诸 ...

  9. 像python一样运行js的__main__

    在测试时,使用单文件进行简单测试既简洁又清晰.js其实也是可以做到的 if (require && require.main == module) { console.log(&quo ...

  10. ios实例开发精品文章推荐(8.13)

    提示用户对产品进行评价 http://www.apkbus.com/android-137752-1-1.html设置UILabel和UITextField的Insets http://www.apk ...