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. ajax 与springmvc交互返回数据

    1.controller将数据封装成json格式返回页面 @RequestMapping("/dataList") public void datalist(CsoftCunsto ...

  2. Win10下安装Ubuntu16.04虚拟机并搭建TensorFlow1.3环境

    本文具体参考资料链接 1.VMware下载安装 百度输入VMware搜索,出现如下界面,点击下载: 此处安装步骤可以网上搜索,也可不用搜索,直接按照按照提示一步一步确认即可完成. 2.Ubuntu16 ...

  3. java笔记整理

    Java 笔记整理 包含内容     Unix Java 基础, 数据库(Oracle jdbc Hibernate pl/sql), web, JSP, Struts, Ajax Spring, E ...

  4. Percona-XtraBackup系列二:备份恢复

    #在备份较大数据量的时候推荐xtrabackup,这个工具比mysqldump要快很多. 一.Xtrabackup介绍 1,Xtrabackup是什么 Xtrabackup是一个对InnoDB做数据备 ...

  5. 【Bugly安卓开发干货】Android APP 高速 Pad 化实现

    Bugly 技术干货系列内容主要涉及移动开发方向.是由 Bugly 邀请腾讯内部各位技术大咖,通过日常工作经验的总结以及感悟撰写而成,内容均属原创.转载请标明出处. 怎样能在最快的时间内,实现一个最新 ...

  6. tensorflow serving 编写配置文件platform_config_file的方法

    1.安装grpc gRPC 的安装: $ pip install grpcio 安装 ProtoBuf 相关的 python 依赖库: $ pip install protobuf 安装 python ...

  7. django之环境变量配置

    1.配置python变量环境,C:\Python27\;C:\Python27\Scripts\ 2.配置django变量环境,C:\Python34\Lib\site-packages\Django ...

  8. sparkmllib矩阵向量

    Spark MLlib底层的向量.矩阵运算使用了Breeze库,Breeze库提供了Vector/Matrix的实现以及相应计算的接口(Linalg).但是在MLlib里面同时也提供了Vector和L ...

  9. linux rpm 安装后 mysql 默认安装目录等信息

    MySQL安装完成后不象SQL Server默认安装在一个目录,它的数据库文件.配置文件和命令文件分别在不同的目录,了解这些目录非常重要,尤其对于Linux的初学者,因为 Linux本身的目录结构就比 ...

  10. Libevent例子(一)

    服务器端 #include<stdio.h> #include<string.h> #include<errno.h> #include<event.h> ...