将大概的流程具体还是看源码

05-14 阅读 0评论

之前看源码的时候呢没有文字整理,想来还是写一个大概的流程吧,具体是无法用文字描述

spring源码真的yyds,数据结构 反射 父子类 接口…玩得溜到飞起  博大精深呐 后期不断喜欢ing!

将大概的流程具体还是看源码

springApplication.run方法

  • 获取了一个ConfigurableApplicationContent
  • spi加载了initializers  listener 

    ps:通过这个context.getBeanFactory => defaultLIstableBeanFactory 父类       

         defaultSingletonBeanRegistry 里面有singletonObjects一级缓存all单例

         这个beanFactory没做什么事,后处理器processor扩展读取configuration/annotation

    prepareRefresh准备工作:校验环境变量/初始化广播器等

    obtainFreshBeanFactory获取configurableListableBeanFactory注册beanDefinitions信息

    prepareBeanFactory

    • 初始化spring组件:类加载器/aware处理器/属性编辑器/表达式解析器
    • beanFactory其他属性
    • LWT系统信息等

      postProcessBeanFactory子类定制,这就到了bean生命周期

      • bean推断构造函数 实例化bean 构造bean对象 有的createBean() 到@i
      •     前有postProcessBeforeInstantiation 后有postProcessAfterInstantiation
      • instantiationAwareBeanPostProcessor可自定义实例化对象过程,postProcessProperties设置属性,@resource这个属性便是利用了这点 操作injectionMetadata反射注入bean
      •      mergedBeanDefinitionPostProcess操作beanDefiniton 可以做数据准备,比如事件event通过接口applicationLIstenerDetector实现mergedBeanDefinitionPostProcess在registerBeanPostProcessors把detector放到beanPostProcessor,就是aop后放入方便获取代理对象 ,这就很妙
      • bean属性注入
      • 各种aware
      •     beanNameAware
      •     beanFactoryAware这个地方咱们@EnableAsync在import了selector中利用AsyncAnnotationBeanPostProcessor实现了,setBeanFactory 创建AsyncAnnotationAdvisor加载了拦截器interceptor invoke dosumbit 利用taskExecutor线程池创建callback执行
      •      applicationContentAware
      • beanPostProcess/postProcessorBeforeInitialization 实例化完成
      • afterPropertiesSet
      • init方法
      • beanPostProcess/postProcessorAfterInitialization 初始化后,咱们事件借助此addApplicationListener到容器
      • aop
      • smartInitializingSingleton咱们事件的注解在afterSingletonInstantiated 容器获取beanName/type  processBean 执行methodIntrosepector 获取@eventListener的信息 借助map 注册到容器
      • 使用bean

        invokeBeanFactoryPostProcessor(beanFactory) 

        registerBeanPostProcessor(beanFactory) 据priorityOrder ordered non 调postProcessorBeanFactory,beanPostProcessor加入到ioc的beanPostProcessor 封装处理

           这也提供了可扩展的空间

        initmessagesource国际化

        initApplicationEventMulticaster事件广播

        onfresh 子类去实现

        registerListener广播器注册监听器

        finishBeanFactoryInitialization 注册单例 bean对象 ,preInstantiateSingletetons 加载单例

        • getBean构造bean对象 父类获取bean对象 校验beanDefinition 构造对象 校验类型 三级缓存加入战场了就

          finishRefresh清理工作

          再上一次图:

          将大概的流程具体还是看源码

          Spr​​​​​​dering之ApplicationListener实现监听原理_实现了applicationlistener-CSDN博客


免责声明
本网站所收集的部分公开资料来源于AI生成和互联网,转载的目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。
文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。

发表评论

快捷回复: 表情:
评论列表 (暂无评论,人围观)

还没有评论,来说两句吧...

目录[+]