從源碼註釋來看,Sring 3.1開始就棄用了XmlBeanFactory,DefaultListableBeanFactory能夠徹底替代它的功能。函數
XmlBeanFactory是DefaultListableBeanFactory的一個擴展,其中,初始化了XmlBeanDefinitionReader,提供了兩個構造函數用來建立XmlBeanFactory Ioc容器。this
public class XmlBeanFactory extends DefaultListableBeanFactory { private final XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this); public XmlBeanFactory(Resource resource) throws BeansException { this(resource, null); } public XmlBeanFactory(Resource resource, BeanFactory parentBeanFactory) throws BeansException { super(parentBeanFactory); this.reader.loadBeanDefinitions(resource); } }
Resource是Spring封裝的I/O的接口類,用來獲取定義bean的Xml文件信息。code
Resource resource = new ClassPathResource("XmlBeanFactory.xml", getClass());
ClassPathResource構造出Resouce,以入參的形式傳遞給XmlBeanFactory的構造函數,經過調用XmlBeanDefinitionReader的loadBeanDefinitions函數對xml文件中定義的bean進行初始化和依賴注入。xml