AnnotationConfigApplicationContext容器中的BeanFactory是DefaultListableBeanFactory

Spring5.3.10
基于AnnotationConfigApplicationContext
本文是AnnotationConfigApplicationContext容器初始化的一部分是针对AbstractApplicationContext#refresh()中下面这行代码的拆解

ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();

AnnotationConfigApplicationContext类图

AnnotationConfigApplicationContext类图
通过类图得发现:AnnotationConfigApplicationContext extends GenericApplicationContext
确认后续的AbstractApplicationContext抽象方法的实现

BeanFactory的创建

//AbstractApplicationContext#refresh()
ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();


//AbstractApplicationContext#obtainFreshBeanFactory()
/**
* Tell the subclass to refresh the internal bean factory.
 * @return the fresh BeanFactory instance
 * @see #refreshBeanFactory()
 * @see #getBeanFactory()
 */
protected ConfigurableListableBeanFactory obtainFreshBeanFactory() {
	refreshBeanFactory();
	return getBeanFactory();
}

AbstractApplicationContext类中refreshBeanFactory()与getBeanFactory() 都是抽象方法,需要子类实现
从AnnotationConfigApplicationContext类图知道AnnotationConfigApplicationContext extends GenericApplicationContext,所以这里的两个方法是GenericApplicationContext中的方法

//GenericApplicationContext#refreshBeanFactory,官方注释这个方法Do nothing,可忽略
/**
* Do nothing: We hold a single internal BeanFactory and rely on callers
 * to register beans through our public methods (or the BeanFactory's).
 * @see #registerBeanDefinition
 */
@Override
protected final void refreshBeanFactory() throws IllegalStateException {
	if (!this.refreshed.compareAndSet(false, true)) {
		throw new IllegalStateException(
				"GenericApplicationContext does not support multiple refresh attempts: just call 'refresh' once");
	}
	this.beanFactory.setSerializationId(getId());
}


//GenericApplicationContext#getBeanFactory
@Override
public final ConfigurableListableBeanFactory getBeanFactory() {
	return this.beanFactory;
}

GenericApplicationContext的构造方法中new DefaultListableBeanFactory()
在这里插入图片描述

DefaultListableBeanFactory类图

在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值