Spring 容器初始化方法

         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();

posted @ 2015-10-14 22:37  常平  阅读(185)  评论(0编辑  收藏  举报