类继承图如下:

spring复习:(17)ClassPathXmlApplicationContext_spring


其中的父类AbstractRefreshableApplicationContext中定义了一个DefaultListableBeanFactory对象:

@Nullable
	private DefaultListableBeanFactory beanFactory;

AbstractApplicationContext中定义了obtainFreshBeanFactory方法

protected ConfigurableListableBeanFactory obtainFreshBeanFactory() {
		refreshBeanFactory();
		return getBeanFactory();
	}

其中调用了getBeanFactory方法。

AbstractApplicationContext的子类AbstractRefreshableApplicationContext实现getBeanFactory方法如下:

public final ConfigurableListableBeanFactory getBeanFactory() {
		synchronized (this.beanFactoryMonitor) {
			if (this.beanFactory == null) {
				throw new IllegalStateException("BeanFactory not initialized or already closed - " +
						"call 'refresh' before accessing beans via the ApplicationContext");
			}
			return this.beanFactory;
		}
	}

该方法实际返回的就是DefaultListableBeanFactory对象