IOC配置文件加载

1绝对路径加载

ApplicationContext ac=new ClassPathXmlApplicationContext("spring.xml");

2相对路径加载

ApplicationContext ac=new FileSystemXmlApplicationContext("E:\\JavaProject\\spring01\\src\\main\\resources\\spring.xml");

3.1多配置文件加载 可变参数 传入多个文件名

ApplicationContext ac=new ClassPathXmlApplicationContext("spring.xml","beans.xml");

3.2多配置文件加载 在总的配置文件中通过import进行导入 加载时需要加载总的配置文件

services为总的配置文件,在其中导入spring和beans配置文件

<import resource="spring.xml"></import>
 <import resource="beans.xml"></import>
ApplicationContext ac=new ClassPathXmlApplicationContext("services.xml");
全部评论

相关推荐

07-17 12:14
门头沟学院 Java
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务