V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
gzk329
V2EX  ›  Java

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

  •  
  •   gzk329 · 2020-09-21 16:58:17 +08:00 · 1052 次点击
    这是一个创建于 1312 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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 的同文件夹下面找,那么这个第四种是什么意思呢?

    2 条回复    2020-09-23 20:40:57 +08:00
    gzk329
        1
    gzk329  
    OP
       2020-09-21 17:00:01 +08:00
    默认都是 相对路径
    那么第二种和第四种是没区别?
    第三种指了一个位置
    是这样吗
    lxk11153
        2
    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
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2708 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 15:52 · PVG 23:52 · LAX 08:52 · JFK 11:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.