Spring Boot 核心原理与源码解析-大纲
原创
©著作权归作者所有:来自51CTO博客作者java硕哥的原创作品,请联系作者获取转载授权,否则将追究法律责任
1、初始化
2、run
2.1、StopWatch
2.2、getRunListeners().starting()
2.3、prepareEnvironment
2.4、printBanner
2.5、createApplicationContext()
2.6、refreshContext(context)
2.7、refreshContext(context)
2.8、afterRefresh(context, applicationArguments)
2.9、listeners.finished(context, null)
附录-run
public ConfigurableApplicationContext run(String... args) {
// 2.1、StopWatch
StopWatch stopWatch = new StopWatch();
stopWatch.start();
ConfigurableApplicationContext context = null;
FailureAnalyzers analyzers = null;
// 2.2
configureHeadlessProperty();
// 2.3 getRunListeners().starting()
SpringApplicationRunListeners listeners = getRunListeners(args);
listeners.starting();
try {
// 2.4、prepareEnvironment
ApplicationArguments applicationArguments = new DefaultApplicationArguments(
args);
ConfigurableEnvironment environment = prepareEnvironment(listeners,
applicationArguments);
// 2.5 打印 Spring Boot logo
Banner printedBanner = printBanner(environment);
// 2.6 创建ApplicationContext
context = createApplicationContext();
analyzers = new FailureAnalyzers(context);
// 2.7
prepareContext(context, environment, listeners, applicationArguments,
printedBanner);
// 2.8
refreshContext(context);
// 2.9
afterRefresh(context, applicationArguments);
// 2.10
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);
}
}