ApplicationContext是对BeanFactory的功能扩展,不但包含了BeanFactory的全部功能,还添加了其他扩展能力。obtainFreshBeanFactory方法是实现BeanFactory的地方,经过这个函数后,ApplicationContext就有了BeanFactory的全部功能。
protected ConfigurableListableBeanFactory obtainFreshBeanFactory() { //初始化beanFactory,读取xml配置,生成BeanDefinition this.refreshBeanFactory(); return this.getBeanFactory(); }protected final void refreshBeanFactory() throws BeansException { if (this.hasBeanFactory()) { this.destroyBeans(); this.closeBeanFactory(); } try { //创建DefaultListableBeanFactory DefaultListableBeanFactory beanFactory = this.createBeanFactory(); beanFactory.setSerializationId(this.getId()); //定制BeanFactory相关属性 this.customizeBeanFactory(beanFactory); //解析配置,比如读取和解析xml, this.loadBeanDefinitions(beanFactory); this.beanFactory = beanFactory; } catch (IOEx