beanFactory 和 applicetion区别

beanFactory:

public void testIOC1() throws Exception{  
        Resource resource =new ClassPathResource("cn/spy/first/applicationContext.xml");  
        @SuppressWarnings("deprecation")  
        BeanFactory factory =new XmlBeanFactory(resource);  
        User user =(User) factory.getBean("user");  
        System.out.println(user.getId()+" : "+user.getUsername());  
          
}  

Applicetion

public void testIOC2() throws Exception{  
        ApplicationContext context= new ClassPathXmlApplicationContext("cn/spy/first/applicationContext.xml");  
        System.out.println("-----容器创建完成-----");  
        User user =(User) context.getBean("user");  
        System.out.println(user.getId()+" : "+user.getUsername());  
}

 

posted @ 2018-03-27 09:44  爱吃醋的工程师  阅读(175)  评论(0编辑  收藏  举报