SpringBoot的启动流程扩展点
阅读说明:
1.如果有排版格式问题,请移步https://www.yuque.com/mrhuang-ire4d/oufb8x/yo5ywqt5eudxvxfc?singleDoc#%20%E3%80%8ASpring%E5%8F%AF%E6%89%A9%E5%B1%95%E6%8E%A5%E5%8F%A3%E6%80%BB%E7%BB%93%E3%80%8B,选择宽屏模式效果更佳。
2.本文为原创文章,转发请注明出处。
SpringBoot的启动流程
启动源码如下:
public ConfigurableApplicationContext run(String... args) {
long startTime = System.nanoTime();
DefaultBootstrapContext bootstrapContext = this.createBootstrapContext();
ConfigurableApplicationContext context = null;
this.configureHeadlessProperty();
SpringApplicationRunListeners listeners = this.getRunListeners(args);
listeners.starting(bootstrapContext, this.mainApplicationClass);
try {
ApplicationArguments applicationArguments = new DefaultApplicationArguments(args);
ConfigurableEnvironment environment = this.prepareEnvironment(listeners, bootstrapContext, applicationArguments);
Banner printedBanner = this.printBanner(environment);
context = this.createApplicationContext();
context.setApplicationStartup(this.applicationStartup);
this.prepareContext(bootstrapContext, context, environment, listeners, applicationArguments, printedBanner);
this.refreshContext(context);
this.afterRefresh(context, applicationArguments);
Duration timeTakenToStartup = Duration.ofNanos(System.nanoTime() - startTime);
if (this.logStartupInfo) {
(new StartupInfoLogger(this.mainApplicationClass)).logStarted(this.getApplicationLog(), timeTakenToStartup);
}
listeners.started(context, timeTakenToStartup);
this.callRunners(context, applicationArguments);
} catch (Throwable var12) {
if (var12 instanceof SpringApplication.AbandonedRunException) {
throw var12;
}
this.handleRunFailure(context, var12, listeners);
throw new IllegalStateException(var12);
}
try {
if (context.isRunning()) {
Duration timeTakenToReady = Duration.ofNanos(System.nanoTime() - startTime);
listeners.ready(context, timeTakenToReady);
}
return context;
} catch (Throwable var11) {
if (var11