首页 > 编程语言 > 详细

Spring 容器初始化方法

时间:2015-10-14 23:30:41      阅读:386      评论:0      收藏:0      [点我收藏+]

         Resource resource = new ClassPathResource("/bean.xml");
         resource = new FileSystemResource("d:/tzspring02/src/bean.xml");
         XmlBeanFactory xmlBeanFactory = new XmlBeanFactory(resource);
        
        /*spring容器加载资源文件的核心类 PathMatchingResourcePatternResolver*/
         ResourcePatternResolver resourceLoader = new PathMatchingResourcePatternResolver();
         Resource resource = resourceLoader.getResource("classpath:bean.xml");//ClassPathResource
         System.out.println(resource.getDescription()+"===="+resource.getFile().getAbsolutePath());
         XmlBeanFactory xmlBeanFactory = new XmlBeanFactory(resource);

 

        System.out.println("########1");
        ApplicationContext application1 = new ClassPathXmlApplicationContext("classpath:/com/easeye/conf/applicationContext.xml");
        Student stu1 = application1.getBean("student",Student.class);
        stu1.ShowInfo();
        
        System.out.println("########2");
        ApplicationContext application2 = new FileSystemXmlApplicationContext("file:D:/Software/apache-tomcat-7.0.59/webapps/SpringDemo/WEB-INF/classes/com/easeye/conf/applicationContext.xml");
        Student stu2 = application2.getBean("student",Student.class);
        stu2.ShowInfo();
        
       
        
        System.out.println("########3");
        ApplicationContext application3 = new AnnotationConfigApplicationContext("com.easeye.test");
        Student stu3 = application3.getBean("student",Student.class);
        stu2.ShowInfo();

Spring 容器初始化方法

原文:http://www.cnblogs.com/c2603/p/4880991.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!