SpringApplication初始化
| 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初始化的更多相关文章
- SpringBoot启动流程分析(一):SpringApplication类初始化过程
SpringBoot系列文章简介 SpringBoot源码阅读辅助篇: Spring IoC容器与应用上下文的设计与实现 SpringBoot启动流程源码分析: SpringBoot启动流程分析(一) ...
- springboot源码解析 - 构建SpringApplication
1 package com.microservice.framework; 2 3 import org.springframework.boot.SpringApplication; 4 impor ...
- Spring Boot 2.0系列文章(七):SpringApplication 深入探索
关注我 转载请务必注明原创地址为:http://www.54tianzhisheng.cn/2018/04/30/springboot_SpringApplication/ 前言 在 Spring B ...
- Spring Boot 启动(一) SpringApplication 分析
Spring Boot 启动(一) SpringApplication 分析 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html ...
- 【附3】springboot源码解析 - 构建SpringApplication
package com.microservice.framework; import org.springframework.boot.SpringApplication; import org.sp ...
- 附3 springboot源码解析 - 构建SpringApplication
package com.microservice.framework; import org.springframework.boot.SpringApplication; import org.sp ...
- SpringBoot SpringApplication底层源码分析与自动装配
目录 抛出问题 @SpringBootApplication注解剖析 SpringApplication类剖析 第一步:配置SpringBoot Bean来源 第二步 :自动推断SpringBoot的 ...
- SpringBoot源码分析之---SpringBoot项目启动类SpringApplication浅析
源码版本说明 本文源码采用版本为SpringBoot 2.1.0BUILD,对应的SpringFramework 5.1.0.RC1 注意:本文只是从整体上梳理流程,不做具体深入分析 SpringBo ...
- SpringBoot源码修炼—系统初始化器
SpringBoot源码修炼-系统初始化器 传统SSM框架与SpringBoot框架简要对比 SSM搭建流程 缺点: 耗时长 配置文件繁琐 需要找合适版本的jar包 SpringBoot搭建流程 优点 ...
随机推荐
- 微软BI 之SSRS 系列 - 使用分组 Group 属性实现基于父子递归关系的汇总报表
基于父子关系的递归结构在公司组织结构里比较常见,基本上都是在一张表里实现的自引用关系.在报表中如果要实现这种效果,并且在这个基础上做一些数据的汇总,可以使用到下面提到的方法. 要实现的效果大致如下 - ...
- websocket与canvas[转]
server端还是用tomcat7的方式客户端 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ...
- linux发送邮件的功能总结
今天添加了发送邮件的功能,总结一下,供以后参考: 1.直接使用管道发送邮件 echo "hello,this is the content of mail.welcome to www.mz ...
- java.lang.AbstractStringBuilder.enlargeBuffer
04-18 10:22:08.585 3653-3653/com.tongyan.lanzhou.rv I/dalvikvm: "main" prio=5 tid=1 RUNNAB ...
- 【转发】Linq To EF添加记录后获取添加的自增ID和叫“ID”的列不是自增列不让插入的问题
1:添加记录后,如何获取新添加的ID的值 比如,一个实体 TestEntity 对应一个表TestEntity(ID主键自增,Name,age),使用linq to ef 添加一条记录后,如何 ...
- Web Service 简介
最近使用ODI的工具箱中的ODIInvokeWebService.因此简单了解下WebService的理论知识. 一.Web Service 简介 Web Service就是可编程的URL,使用标准的 ...
- 浅谈Spring的PropertyPlaceholderConfigurer
大型项目中,我们往往会对我们的系统的配置信息进行统一管理,一般做法是将配置信息配置与一个cfg.properties的文件中,然后在我们系统初始化的时候,系统自动读取cfg.properties配置文 ...
- 整合ssm框架之配置文件
原文:https://blog.csdn.net/zwyanqing/article/details/53039591 ssm整合 一.applicationContext.xml 1.配置数据源 & ...
- JSONObject.parseObject(jsonStr);和JSONObject.fromObject(jsonStr);
虽然都是返回JSONObject,但是 JSONObject.parseObject(jsonStr);这个方法需要导入import com.alibaba.fastjson.JSONObject; ...
- HTTP代理服务器
一.什么是代理服务器 代理服务器英文全称是Proxy Server,其功能就是代理网络用户去取得网络信息.形象的说:它是网络信息的中转站. 在一般情况下,我们使用网络浏览器直接去连接其他Interne ...