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
相关推荐
盘子素几秒前
前端实现跳转子系统,但限制只能跳转一次
前端·javascript
悟空码字几秒前
三步搞定短信验证码!SpringBoot集成阿里云短信实战
java·spring boot·后端
Anita_Sun几秒前
Lodash 源码解读与原理分析 - Lodash 前世今生:设计原则与演进脉络
前端
码农爱学习1 分钟前
C语言结构体对齐是怎么计算
java·c语言·数据库
爱吃羊的老虎4 分钟前
Streamlit:快速创建应用界面,无需了解 Web 开发
前端·python
黎雁·泠崖5 分钟前
吃透Java操作符入门:分类差异+进制转换+原反补码 核心前置知识(Java&C对比)
java·c语言·开发语言
天天摸鱼的java工程师5 分钟前
volatile 关键字底层原理:为什么它不能保证原子性?
java·后端
钟良堂5 分钟前
Java完整实现 MinIO 对象存储搭建+封装全套公共方法+断点上传功能
java·minio·断点上传
满栀5857 分钟前
三级联动下拉框
开发语言·前端·jquery
名字不好奇9 分钟前
C++虚函数表失效???
java·开发语言·c++