instances = createSpringFactoriesInstances(type, parameterTypes, classLoader, args, names);
+ // 按@Order注解进行排序,值约小的越靠前
+ AnnotationAwareOrderComparator.sort(instances);
+ return instances;
+ }
+```
+
+
+
+##### 6、将初始化器排序好的实例注册到Spring容器中
+
+```java
+ public void setInitializers(Collection extends ApplicationContextInitializer>> initializers) {
+ this.initializers = new ArrayList<>();
+ // 将初始化器的实例添加到Spring容器中
+ this.initializers.addAll(initializers);
+ }
+```
+
+
+
+#### 总结
+
+- SpringFactoriesLoader作用: SpringBoot框架中从类路径jar包中读取特定的文件(META-INF/spring.factories)实现扩展类的载入
+
+
+
+- LoadFactories流程
+
+
diff --git "a/springboot-source-code-analysis/(4)\347\263\273\347\273\237\345\210\235\345\247\213\345\214\226\345\231\250\350\247\243\346\236\220.md" "b/springboot-source-code-analysis/(4)\347\263\273\347\273\237\345\210\235\345\247\213\345\214\226\345\231\250\350\247\243\346\236\220.md"
new file mode 100644
index 0000000..b293a0e
--- /dev/null
+++ "b/springboot-source-code-analysis/(4)\347\263\273\347\273\237\345\210\235\345\247\213\345\214\226\345\231\250\350\247\243\346\236\220.md"
@@ -0,0 +1,215 @@
+### 系统初始化器解析
+
+#### 1、ApplicationContextInitializer作用
+
+```java
+/**
+ * Callback interface for initializing a Spring {@link ConfigurableApplicationContext}
+ * prior to being {@linkplain ConfigurableApplicationContext#refresh() refreshed}.
+ *
+ * Typically used within web applications that require some programmatic initialization
+ * of the application context. For example, registering property sources or activating
+ * profiles against the {@linkplain ConfigurableApplicationContext#getEnvironment()
+ * context's environment}. See {@code ContextLoader} and {@code FrameworkServlet} support
+ * for declaring a "contextInitializerClasses" context-param and init-param, respectively.
+ *
+ *
{@code ApplicationContextInitializer} processors are encouraged to detect
+ * whether Spring's {@link org.springframework.core.Ordered Ordered} interface has been
+ * implemented or if the @{@link org.springframework.core.annotation.Order Order}
+ * annotation is present and to sort instances accordingly if so prior to invocation.
+ *
+ * @author Chris Beams
+ * @since 3.1
+ * @param the application context type
+ * @see org.springframework.web.context.ContextLoader#customizeContext
+ * @see org.springframework.web.context.ContextLoader#CONTEXT_INITIALIZER_CLASSES_PARAM
+ * @see org.springframework.web.servlet.FrameworkServlet#setContextInitializerClasses
+ * @see org.springframework.web.servlet.FrameworkServlet#applyInitializers
+ */
+public interface ApplicationContextInitializer {
+
+ /**
+ * Initialize the given application context.
+ * @param applicationContext the application to configure
+ */
+ void initialize(C applicationContext);
+}
+
+```
+
+- 上下文刷新即refersh方法前调用;
+- 用来编码设置一些属性变量,通常用在web环境中;
+- 可以通过order接口进行排序;
+
+
+
+#### 2、ApplicationContextInitializer调用点,通过SpringFactoriesLoder中的this.initializers进行初始化
+
+
+
+- 步骤一:在刷新上下文前,调用prepareContext#()准备上下文的方法
+
+```java
+public ConfigurableApplicationContext run(String... args) {
+ StopWatch stopWatch = new StopWatch();
+ stopWatch.start();
+ ConfigurableApplicationContext context = null;
+ Collection exceptionReporters = new ArrayList<>();
+ configureHeadlessProperty();
+ SpringApplicationRunListeners listeners = getRunListeners(args);
+ listeners.starting();
+ try {
+ ApplicationArguments applicationArguments = new DefaultApplicationArguments(args);
+ ConfigurableEnvironment environment = prepareEnvironment(listeners, applicationArguments);
+ configureIgnoreBeanInfo(environment);
+ Banner printedBanner = printBanner(environment);
+ context = createApplicationContext();
+ exceptionReporters = getSpringFactoriesInstances(SpringBootExceptionReporter.class,
+ new Class[] { ConfigurableApplicationContext.class }, context);
+ // 准备上下文
+ prepareContext(context, environment, listeners, applicationArguments, printedBanner);
+ // 刷新上下文
+ refreshContext(context);
+ 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);
+ }
+ return context;
+ }
+```
+
+- 步骤二:调用初始化器 applyInitializers(context) 方法
+
+```java
+ private void prepareContext(ConfigurableApplicationContext context, ConfigurableEnvironment environment,
+ SpringApplicationRunListeners listeners, ApplicationArguments applicationArguments, Banner printedBanner) {
+ context.setEnvironment(environment);
+ postProcessApplicationContext(context);
+ // 调用初始化器方法
+ applyInitializers(context);
+ listeners.contextPrepared(context);
+ if (this.logStartupInfo) {
+ logStartupInfo(context.getParent() == null);
+ logStartupProfileInfo(context);
+ }
+ // Add boot specific singleton beans
+ ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
+ beanFactory.registerSingleton("springApplicationArguments", applicationArguments);
+ if (printedBanner != null) {
+ beanFactory.registerSingleton("springBootBanner", printedBanner);
+ }
+ if (beanFactory instanceof DefaultListableBeanFactory) {
+ ((DefaultListableBeanFactory) beanFactory)
+ .setAllowBeanDefinitionOverriding(this.allowBeanDefinitionOverriding);
+ }
+ // Load the sources
+ Set