您的位置:首页 > 移动开发

Spring中操作applicationContext.xml

2010-08-05 15:48 429 查看
ApplicationContext ac = null;



方法1. 在classpath根路径查找
ac = new ClassPathXmlApplicationContext("your.xml");



方法2. 在classpath下的test文件夹下查找
ac = new ClassPathXmlApplicationContext("classpath:test/your.xml");



方法3. 在某个类所在的路径中查找
ac = new ClassPathXmlApplicationContext("your.xml",HelloWorld.class);



方法4. 通过URL定位查找
ac = new ClassPathXmlApplicationContext("file:D:/aaa/bbb/your.xml");



方法5. 直接传入路径:
ac = new FileSystemXmlApplicationContext("D:/aaa/bbb/your.xml");



方法6. 指定多个配置文件
ac = new ClassPathXmlApplicationContext(
new String[]{"test1.xml","aaa/test2.xml"}
);

============

classpath*:
查找所有路径下的test.xml
ac = new ClassPathXmlApplicationContext("classpath*:*/test.xml");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: