Spring载入配置文件applicationContext.xml的几种方式
2013-04-14 12:06
603 查看
第一种方式:
ClassPathResource cpr = new ClassPathResource("applicationContext.xml");
XmlBeanFactory factory = new XmlBeanFactory(cpr);
Person chinese = (Person) factory.getBean("chinese");//参数为配置文件中的id值
System.out.println(chinese.sayGoodBye("张三"));
第二中方式:(多个配置文件,用数组)
ApplicationContext ac = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml",
"applicationContext2.xml"});
第三种方式:(java的文件系统)
ApplicationContext ac = new FileSystemXmlApplicationContext("src/applicationContext.xml");
Person chinese = (Person) ac.getBean("chinese");//参数为配置文件中的id值
System.out.println(chinese.sayGoodBye("张三"));
ClassPathResource cpr = new ClassPathResource("applicationContext.xml");
XmlBeanFactory factory = new XmlBeanFactory(cpr);
Person chinese = (Person) factory.getBean("chinese");//参数为配置文件中的id值
System.out.println(chinese.sayGoodBye("张三"));
第二中方式:(多个配置文件,用数组)
ApplicationContext ac = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml",
"applicationContext2.xml"});
第三种方式:(java的文件系统)
ApplicationContext ac = new FileSystemXmlApplicationContext("src/applicationContext.xml");
Person chinese = (Person) ac.getBean("chinese");//参数为配置文件中的id值
System.out.println(chinese.sayGoodBye("张三"));
相关文章推荐
- Spring加载配置文件applicationContext.xml的方式
- Spring配置文件applicationContext.xml的两种拆分方式
- 读取Spring的配置文件applicationContext.xml几种方法
- Spring配置文件applicationContext.xml的两种拆分方式
- Spring 配置文件applicationContext.xml
- applicationContext.xml import spring模块配置文件
- spring配置文件:applicationContext.xml
- spring配置文件详解(applicationContext.xml详解)
- 【Spring学习笔记-2】Myeclipse下第一个Spring程序-通过ClassPathXmlApplicationContext加载配置文件
- Spring applicationContext.xml 文件 路径配置 (2)
- 要想看懂 spring 的配置文件:ApplicationContext.xml 第一步
- spring applicationContext.xml 配置文件 详解
- spring配置文件applicationContext.xml
- applicationContext.xml import spring模块配置文件
- Spring的配置文件,可以用applicationContext.xml+applicationContext.properties
- spring中读取xml配置文件、获取bean的几种方式
- spring配置文件applicationContext.xml不能提示的解决方法
- spring applicationContext.xml 配置文件 详解
- Spring Data JPA applicationContext.xml 配置文件报错的解决办法
- spring配置文件applicationContext.xml不能自动提示的解决方法