Spring中操作applicationContext.xml

来源:互联网 发布:沼泽人思想实验知乎 编辑:程序博客网 时间:2024/06/05 04:39

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

原创粉丝点击