springioc容器学习第一天第二篇

xiaoxiao2021-02-28  97

package com.text.beanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.ClassPathResource; import com.spring.controller.FristBeanController; import com.spring.controller.HelloController; /** * 了解XmlBeanFactory的实现 * XmlBeanFactory继承了DefaultListableBeanFactory * 其功能的实现是建立在DefaultListableBeanFactory这个基本容器基础上的, * 并在这个基础上实现了诸如xml读取的附加功能; * XmlBeanFactory在通过构造方法实例化时,需要获取resource对象, * 并对XmlBeanDefinitionReader对象初始化 * 可以参考ProgrammeGetBean进行理解 * * @author wangshuaimin */ public class XmlBeanFactoryText { public static void main(String[] args) { ClassPathResource resource = new ClassPathResource("spring-beans.xml"); XmlBeanFactory factory = new XmlBeanFactory(resource); //测试用的bean HelloController hello = (HelloController) factory.getBean("hellocontroller"); FristBeanController frist = (FristBeanController) factory.getBean("fristBeanController"); } /** * XmlBeanFactory的实现源码 */ // 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); // } // // } }
转载请注明原文地址: https://www.6miu.com/read-57899.html

最新回复(0)