XmlBeanFactory过期问题

package center.module.datamanager;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionReader;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

public class BeanFactoryTest {

    public void testSimpleLoad() {
        // 过时处理逻辑,XmlBeanFactory在3.1以后已经被废弃,不再推荐使用
        BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("beanFactoryTest.xml"));

        // 当前方案一:BeanFactory在启动的时候不会创建bean实例,而是在getBean()的时候,才会创建bean的实例
        Resource resource = new ClassPathResource("applicationContext.xml");
        beanFactory = new DefaultListableBeanFactory();
        BeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) beanFactory);
        beanDefinitionReader.loadBeanDefinitions(resource);

        // 当前方案二:使用ApplicationContext
        // (ApplicationContext在读取配置文件的时候,配置文件中的bena就会被初始化(不考虑bean的作用域))
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");

    }
}

猜你喜欢

转载自blog.csdn.net/u013412772/article/details/79956346