项目的初始化启动**
springboot吧
全部回复
仅看楼主
level 1

分析完(newSpringApplication(primarySources)).run(args)源码前一部分SpringApplication实例对象的初始化创建后,查看run(args)方法执行的项目初始化启动过程,核心代码具体如下:
```java
public ConfigurableApplicationContextrun(String... args) {
StopWatchstopWatch = new StopWatch();
stopWatch.start();
ConfigurableApplicationContextcontext = null;
Collection<SpringBootExceptionReporter>exceptionReporters = new ArrayList();
this.configureHeadlessProperty();
// 第一步:获取并启动监听器
SpringApplicationRunListenerslisteners = this.getRunListeners(args);
listeners.starting();
CollectionexceptionReporters;
try{
ApplicationArgumentsapplicationArguments =
new DefaultApplicationArguments(args);
// 第二步:根据SpringApplicationRunListeners以及参数来准备环境
ConfigurableEnvironmentenvironment =
this.prepareEnvironment(listeners,applicationArguments);
this.configureIgnoreBeanInfo(environment);
// 准备Banner打印器 - 就是启动Spring Boot的时候打印在console上的ASCII艺术字体
BannerprintedBanner = this.printBanner(environment);
//第三步:创建Spring容器
context= this.createApplicationContext();
exceptionReporters=
this.getSpringFactoriesInstances(SpringBootExceptionReporter.class,
newClass[]{ConfigurableApplicationContext.class}, new Object[]{context});
这些内容,是从拉勾教育的《Java工程师高薪训练营》里学到的,课程内容非常全面,还有拉勾的内推大厂服务,推荐你也看看。
2020年07月03日 02点07分 1
1