gzk329
V2EX  ›  Java

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

  •  
  •   gzk329 · Sep 21, 2020 · 1533 views
    This topic created in 2070 days ago, the information mentioned may be changed or developed.
    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 replies    2020-09-23 20:40:57 +08:00
    gzk329
        1
    gzk329  
    OP
       Sep 21, 2020
    默认都是 相对路径
    那么第二种和第四种是没区别?
    第三种指了一个位置
    是这样吗
    lxk11153
        2
    lxk11153  
       Sep 23, 2020
    - 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
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   845 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 21:33 · PVG 05:33 · LAX 14:33 · JFK 17:33
    ♥ Do have faith in what you're doing.