The type XmlBeanFactory is deprecated,XmlBeanFactory在3.1以后已经被废弃,不再推荐使用
BeanFactory factory = new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));
解决方案:
1、在不改变处理逻辑的基础上,改为
Resource resource=new ClassPathResource("applicationContext.xml");
BeanFactory factory=new DefaultListableBeanFactory();
BeanDefinitionReader bdr=new XmlBeanDefinitionReader((BeanDefinitionRegistry) factory1);
bdr.loadBeanDefinitions(resource);
BeanFactory在启动的时候,不会创建bean的实例,而是在getBean()的时候,才会创建Bean的实例
factory.getBean("beanClass");
2、使用ApplicationContext
ApplicationContext sc = new ClassPathXmlApplicationContext("applicationContext.xml");
ApplicationContext在读取配置文件的时候,配置文件中的bean就会被实例化(不考虑bean的作用域)
上代码
BeanCla