spring之applicationContext、beanFactory

来源:互联网 发布:数码宝贝网络侦探能力 编辑:程序博客网 时间:2024/05/16 02:37

1.ApplicationContext 是 BeanFactory接口的子接口

2.beanFactory:

        BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));  
        HelloService helloService4 = (HelloService) beanFactory.getBean("helloService");  

3.applicationContext:

         ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml"); 
         HelloService helloService2 = (HelloService) applicationContext.getBean("helloService"); 

比较:

1)BeanFactory 采用的是延迟加载,第一次getBean的时候才会初始化Bean,如有异常,这个时候才跑出来。而applicationContext初始化的时候,就开始检验,如果有问             题,就直接抛出来
2)ApplicationContext是对BeanFactory的扩展(也可以延迟加载,lazy-init=true),提供了更多的功能
      国际化处理
      事件传递
      Bean自动装配
      各种不同应用层的Context实现(webApplicationContext实现针对web)






原创粉丝点击