SpringBoot:class变成beanDefinition, beanDefinition变成bean

跟进AbstractApplicationContext的refresh方法:

    public void refresh() throws BeansException, IllegalStateException {synchronized(this.startupShutdownMonitor) {this.prepareRefresh();ConfigurableListableBeanFactory beanFactory = this.obtainFreshBeanFactory();this.prepareBeanFactory(beanFactory);try {this.postProcessBeanFactory(beanFactory);this.invokeBeanFactoryPostProcessors(beanFactory);this.registerBeanPostProcessors(beanFactory);this.initMessageSource();this.initApplicationEventMulticaster();this.onRefresh();this.registerListeners();this.finishBeanFactoryInitialization(beanFactory);this.finishRefresh();} catch (BeansException var9) {if (this.logger.isWarnEnabled()) {this.logger.warn("Exception encountered during context initialization - cancelling refresh attempt: " + var9);}this.destroyBeans();this.cancelRefresh(var9);throw var9;} finally {this.resetCommonCaches();}}}

1、this.invokeBeanFactoryPostProcessors(beanFactory)方法将class 变成 beanDefinition。

2、在执行finishBeanFactoryInitialization(beanFactory); 方法前,所有的配置类都已经变成了 beanDefinition 保存 beanFactory 的 beanDefinitionMap 中。现在执行 finishBeanFactoryInitialization(beanFactory)方法是为了让 所有的 beanDefinition 变成 bean。

大体的流程是:遍历 beanDefinitionMap 中的每一个 beanDefinition,从里面拿出 className,以 className 为依据,去 beanFactory 的 singletonObject 属性中去拿对应名字的 bean。如果能拿到,那就表示该 beanDefinition 已经变成 bean了,否则就用 beanDefinition 创建新 bean 并保存到 singletonObject 中。

SpringBoot:class变成beanDefinition, beanDefinition变成bean相关推荐

  1. SpringBoot - yml与properties配置文件及bean赋值

    SpringBoot - yml与properties配置文件及bean赋值 ① SpringBoot的配置文件 SpringBoot使用一个全局的配置文件,配置文件名是固定的 : applicati ...

  2. 【学习笔记】springBoot中获取sping管理的bean

    文章目录 一.使用场景 二.springBoot中获取sping管理的bean 2.1 生成工具类SpringContextUtil 2.2 使用工具类SpringContextUtil 2.3 注意 ...

  3. springboot available: expected at least 1 bean which qualifies as autowire candidate

    springboot available: expected at least 1 bean which qualifies as autowire candidate 奇葩问题 问题: 报启动失败, ...

  4. SpringBoot启动问题:No qualifying bean of type ‘XXX‘ available: ...

    **记录:**SpringBoot 启动问题:No qualifying bean of type 'XX' available: expected at least 1 bean which qua ...

  5. SpringBoot框架(4)-- 类装配及Bean装配监听器

    1.普通方式装配类对象   (1)添加带有@Bean注解的方法 User.java(带@Component注解) 1 package com.demo.boot.bootenable.beanDemo ...

  6. SpringBoot学习之@Configuration注解和@Bean注解

    @Configuration 1.@Configuration注解底层是含有@Component ,所以@Configuration 具有和 @Component 的作用. 2.@Configurat ...

  7. 关于springboot工具类中@Autowired注入bean,用static直接修饰,静态方法使用bean时报空指针异常错误...

    错误场景: springboot + mybatis 在工具类的静态方法中,需要使用mapper(其他bean也一样),所以最开始直接使用@Autowired进行了注入,代码如下: @Autowire ...

  8. autowired 静态方法使用_关于springboot工具类中@Autowired注入bean,用static直接修饰,静态方法使用bean时报空指针异常错误...

    错误场景: springboot + mybatis 在工具类的静态方法中,需要使用mapper(其他bean也一样),所以最开始直接使用@Autowired进行了注入,代码如下: @Autowire ...

  9. spring springboot websocket 不能注入( @Autowired ) service bean 报 null 错误

    spring 或 springboot 的 websocket 里面使用 @Autowired 注入 service 或 bean 时,报空指针异常,service 为 null(并不是不能被注入). ...

最新文章

  1. Udacity机器人软件工程师课程笔记(十六)-机械臂仿真控制实例(其一)-Gazebo、RViz和Moveit!
  2. java调用PageOffice生成word
  3. UIBezierPath的使用(持续更新)
  4. 深入解读阿里云Redis开发规范:不要只会setget
  5. 【C 语言】文件操作 ( 写文本文件 | Qt 创建 C 语言命令行项目 )
  6. ansible(基础)
  7. STL 之find,find_if,find_end,find_first_of
  8. 为什么苹果不再需要谷歌地图?
  9. 解决Windows中PLSQL连接虚拟机中Oracle缓慢的问题
  10. 软著申请时的软件说明书如何制作
  11. 工程师,你的钱究竟从哪来?
  12. Linux 基础命令3 shell
  13. 【Linux】Linux的信号量集
  14. 中国地图里暗藏的天机
  15. java奖学金课设系统_java毕业设计_springboot框架的基于奖学金评定系统
  16. php的include once,php include_once的使用方法详解
  17. 外卖点餐管理系统源码
  18. 【Python 基础教程】Python语言中的数据类型(二)
  19. Applied ADO.NET: Building Data-Driven Solutions
  20. 进销存设计与分析_库存汇总表(13)

热门文章

  1. 表格固定行(某几列固定)
  2. NAS DAS SAN三种存储方式的比较
  3. 【调剂】贵州大学大数据与信息工程学院欢迎你
  4. MATLAB自适应中值滤波
  5. sql同时查询出明细和汇总
  6. 2020年云南专升本各院校招生人数及学费情况
  7. 尚硅谷微信小程序开发 仿网易云音乐App 小程序 后端接口服务器搭建
  8. CVE-2016-6816、CVE-2016-8735、CVE-2016-8745、CVE-2017-5647
  9. 强化学习(一)——强化学习概念、方法汇总及游戏例子
  10. 思科设备SSH登陆详细配置过程