Springboot起動構成原理(起動原理、運転フロー、自動構成原理)
12876 ワード
Springboot起動構成原理(起動原理、運転フロー、自動構成原理)
1.いくつかの重要なイベントコールバックメカニズムに関連するインタフェース
(1)、ApplicationContextInitializer.initialize()
(2)、SpringApplicationRunListener
(3)、ApplicationRunner
(4)、CommandLineRunner
2.プロセスの開始
(1)SpringApplicationオブジェクトの作成
この手順は、次の2つのステップに分けられます.
a.SpringApplicationオブジェクトの作成、b.runメソッドの実行
(2)アプリケーションの起動
未完待续...
1.いくつかの重要なイベントコールバックメカニズムに関連するインタフェース
(1)、ApplicationContextInitializer.initialize()
(2)、SpringApplicationRunListener
(3)、ApplicationRunner
(4)、CommandLineRunner
2.プロセスの開始
(1)SpringApplicationオブジェクトの作成
この手順は、次の2つのステップに分けられます.
a.SpringApplicationオブジェクトの作成、b.runメソッドの実行
public static ConfigurableApplicationContext run(Class<?> primarySource, String... args) {
return run(new Class[]{primarySource}, args);
}
public static ConfigurableApplicationContext run(Class<?>[] primarySources, String[] args) {
return (new SpringApplication(primarySources)).run(args);
}
(2)アプリケーションの起動
/**
* Run the Spring application, creating and refreshing a new
* {@link ApplicationContext}.
* @param args the application arguments (usually passed from a Java main method)
* @return a running {@link ApplicationContext}
*/
public ConfigurableApplicationContext run(String... args) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
ConfigurableApplicationContext context = null;
Collection<SpringBootExceptionReporter> exceptionReporters = new ArrayList<>();
configureHeadlessProperty();
// SpringApplicationRunListeners; MATA-INFO/spring.factories
SpringApplicationRunListeners listeners = getRunListeners(args);
// SpringApplicationRunListeners.starting();
listeners.starting();
try {
//
ApplicationArguments applicationArguments = new DefaultApplicationArguments(args);
//
ConfigurableEnvironment environment = prepareEnvironment(listeners, applicationArguments);
configureIgnoreBeanInfo(environment);
//
Banner printedBanner = printBanner(environment);
// ApplicationContext
context = createApplicationContext();
exceptionReporters = getSpringFactoriesInstances(SpringBootExceptionReporter.class,
new Class[] { ConfigurableApplicationContext.class }, context);
// (ApplicationContextInitializer)
prepareContext(context, environment, listeners, applicationArguments, printedBanner);
// ,ioc
refreshContext(context);
// ioc ApplicationRunner CommandLineRunner (ApplicationRunner ,CommandLineRunner )
afterRefresh(context, applicationArguments);
stopWatch.stop();
if (this.logStartupInfo) {
new StartupInfoLogger(this.mainApplicationClass).logStarted(getApplicationLog(), stopWatch);
}
listeners.started(context);
callRunners(context, applicationArguments);
}
catch (Throwable ex) {
handleRunFailure(context, ex, exceptionReporters, listeners);
throw new IllegalStateException(ex);
}
try {
listeners.running(context);
}
catch (Throwable ex) {
handleRunFailure(context, ex, exceptionReporters, null);
throw new IllegalStateException(ex);
}
// springboot ioc
return context;
}
未完待续...