SpringBoot:class变成beanDefinition, beanDefinition变成bean
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相关推荐
- SpringBoot - yml与properties配置文件及bean赋值
SpringBoot - yml与properties配置文件及bean赋值 ① SpringBoot的配置文件 SpringBoot使用一个全局的配置文件,配置文件名是固定的 : applicati ...
- 【学习笔记】springBoot中获取sping管理的bean
文章目录 一.使用场景 二.springBoot中获取sping管理的bean 2.1 生成工具类SpringContextUtil 2.2 使用工具类SpringContextUtil 2.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 奇葩问题 问题: 报启动失败, ...
- SpringBoot启动问题:No qualifying bean of type ‘XXX‘ available: ...
**记录:**SpringBoot 启动问题:No qualifying bean of type 'XX' available: expected at least 1 bean which qua ...
- SpringBoot框架(4)-- 类装配及Bean装配监听器
1.普通方式装配类对象 (1)添加带有@Bean注解的方法 User.java(带@Component注解) 1 package com.demo.boot.bootenable.beanDemo ...
- SpringBoot学习之@Configuration注解和@Bean注解
@Configuration 1.@Configuration注解底层是含有@Component ,所以@Configuration 具有和 @Component 的作用. 2.@Configurat ...
- 关于springboot工具类中@Autowired注入bean,用static直接修饰,静态方法使用bean时报空指针异常错误...
错误场景: springboot + mybatis 在工具类的静态方法中,需要使用mapper(其他bean也一样),所以最开始直接使用@Autowired进行了注入,代码如下: @Autowire ...
- autowired 静态方法使用_关于springboot工具类中@Autowired注入bean,用static直接修饰,静态方法使用bean时报空指针异常错误...
错误场景: springboot + mybatis 在工具类的静态方法中,需要使用mapper(其他bean也一样),所以最开始直接使用@Autowired进行了注入,代码如下: @Autowire ...
- spring springboot websocket 不能注入( @Autowired ) service bean 报 null 错误
spring 或 springboot 的 websocket 里面使用 @Autowired 注入 service 或 bean 时,报空指针异常,service 为 null(并不是不能被注入). ...
最新文章
- Udacity机器人软件工程师课程笔记(十六)-机械臂仿真控制实例(其一)-Gazebo、RViz和Moveit!
- java调用PageOffice生成word
- UIBezierPath的使用(持续更新)
- 深入解读阿里云Redis开发规范:不要只会setget
- 【C 语言】文件操作 ( 写文本文件 | Qt 创建 C 语言命令行项目 )
- ansible(基础)
- STL 之find,find_if,find_end,find_first_of
- 为什么苹果不再需要谷歌地图?
- 解决Windows中PLSQL连接虚拟机中Oracle缓慢的问题
- 软著申请时的软件说明书如何制作
- 工程师,你的钱究竟从哪来?
- Linux 基础命令3 shell
- 【Linux】Linux的信号量集
- 中国地图里暗藏的天机
- java奖学金课设系统_java毕业设计_springboot框架的基于奖学金评定系统
- php的include once,php include_once的使用方法详解
- 外卖点餐管理系统源码
- 【Python 基础教程】Python语言中的数据类型(二)
- Applied ADO.NET: Building Data-Driven Solutions
- 进销存设计与分析_库存汇总表(13)