@yulongsun
2018-06-28T04:51:46.000000Z
字数 1327
阅读 856
SpringIOC分析系列
题目:Spring的两大容器ApplicationContext和BeanFactory的区别?
1、BeanFactory获取Bean()
@Testpublic void testBeanFactoryCreateBean() {ClassPathResource resource = new ClassPathResource("spring-bean.xml");XmlBeanFactory factory = new XmlBeanFactory(resource);//System.out.println("begin get bean.");factory.getBean("bean");System.out.println("end get bean.");}
日志

2、 ApplicationContext获取Bean()
@Testpublic void testApplicationContextCreateBean() {ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring-bean.xml");//System.out.println("begin get bean.");context.getBean("bean");System.out.println("end get bean.");}
日志


1、ClassPathXmlApplicationContext#refresh()

2、AbstractApplicationContext#refresh()

3、AbstractApplicationContext#refresh()#finishBeanFactoryInitialization()

4、BeanFactory#preInstantiateSingletons()#getBean()
