Spring 相关 总结从多个 xml 文件中加载 bean 的几种方法

2020-09-21 16:58:17 +08:00
 gzk329
ApplicationContext ctx =
    new ClassPathXmlApplicationContext("classpath:*conf-*.xml");
//或者
ApplicationContext ctx =
    new ClassPathXmlApplicationContext("classpath*:a.xml,b.xml");
//或者
ApplicationContext ctx = new ClassPathXmlApplicationContext(
    new String[] {"services.xml", "daos.xml"}, MessengerService.class);
//或者
ApplicationContext ctx = new ClassPathXmlApplicationContext(
    new String[] {"services.xml", "daos.xml"});

这个第三种是从 MesssengerService.class 的同文件夹下面找,那么这个第四种是什么意思呢?

1052 次点击
所在节点    Java
2 条回复
gzk329
2020-09-21 17:00:01 +08:00
默认都是 相对路径
那么第二种和第四种是没区别?
第三种指了一个位置
是这样吗
lxk11153
2020-09-23 20:40:57 +08:00
- new ClassPathXmlApplicationContext( 这里不用带 classpath:前缀的
- 1 2 的区别 https://blog.csdn.net/qq_30038111/article/details/82116559
- 4 相对 classpath 下的"services.xml", "daos.xml"

----
自己看源码或者文档 https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/core.html#resources-app-ctx

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/709100

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX