createApplicationContext 加载各种PostProcessor

java 复制代码
public ConfigurableApplicationContext run(String... args) {
   StopWatch stopWatch = new StopWatch();
   stopWatch.start();
   ConfigurableApplicationContext context = null;
   Collection<SpringBootExceptionReporter> 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;
}
  1. createApplicationContext 加载各种PostProcessor
  2. prepareContext 加载ServerMain类
  3. refreshContext 调用 1步加载的PostProcessor然后实例化
  4. PostProcessor实例化后就去加载其他的类,生成Beandefinition
java 复制代码
ConfigurationClassPostProcessor

PostProcessorRegistrationDelegate#invokeBeanFactoryPostProcessors

ClassPathScanningCandidateComponentProvider
相关推荐
在下雨5997 分钟前
项目讲解1
开发语言·数据结构·c++·算法·单例模式
再努力"亿"点点10 分钟前
Sklearn(机器学习)实战:鸢尾花数据集处理技巧
开发语言·python
じòぴé南冸じょうげん13 分钟前
小程序的project.private.config.json是无依赖文件,那可以删除吗?
前端·小程序·json
渣哥19 分钟前
我和Java 8 Stream相爱相杀的那些年
java
爱吃烤鸡翅的酸菜鱼21 分钟前
【Spring】原理解析:Spring Boot 自动配置
java·spring boot
小白兔35321 分钟前
一文讲通Unicode规范、UTF-8与UTF-16编码及在Java中的验证
java
会豪22 分钟前
Electron主进程渲染进程如何优雅的进行通信
前端
jianghaha201123 分钟前
前端 Word 模板参入特定数据 并且下载
前端·word
跟橙姐学代码23 分钟前
轻松搞定 Python 模块与包导入:新手也能秒懂的入门指南
前端·python·ipython
十八旬27 分钟前
苍穹外卖项目实战(day7-1)-缓存菜品和缓存套餐功能-记录实战教程、问题的解决方法以及完整代码
java·数据库·spring boot·redis·缓存·spring cache