zoukankan      html  css  js  c++  java
  • [Js-Spring]为应用指定多个 Spring 配置文件

    为 Spring 指定多个平等关系的配置文件

    第一种方式:通配符指定文件(这也是为什么我们建议将所有配置文件命名有规则的原因)

    第二种方式:加载多个配置路径,采用 ApplicationContext 的可变长参数构造方法

    第三种方式:于第二种类似,不过调用的是 ApplicationContext 的参数为字符串数组的构造方法

    // 加载Spring配置文件,创建Spring容器对象
    //    第一种方式
    String resource = "com/neu/di15/spring-*.xml"; 
    ApplicationContext ac = new ClassPathXmlApplicationContext(resource);
    /*    第二种方式
    String resource1 = "com/neu/di15/spring-base.xml"; 
    String resource2 = "com/neu/di15/spring-beans.xml";
    ApplicationContext ac = new ClassPathXmlApplicationContext(resource1, resource2);
     */
    /*    第三种方式
    String resource1 = "com/neu/di15/spring-base.xml";
    String resource2 = "com/neu/di15/spring-beans.xml";
    String[] resources = { resource1, resource2 };
    ApplicationContext ac = new ClassPathXmlApplicationContext(resources);
    */

    为 Spring 指定多个包含关系的配置文件

    在总的配置文件中导入子配置文件即可,可以分别导入,或者通配符

    <!--
    <import resource="spring-base.xml"/>
    <import resource="spring-beans.xml"/>
     -->
    <import resource="spring-*.xml"/>
  • 相关阅读:
    锁定键盘、鼠标 武胜
    Begin a forensics investigation with WinHex 武胜
    vc++ 访问php webService
    VC xml解析笔记
    关于php Soap一些错误。
    ZendStudio php WebService制作一:简单WebService Demo
    vc各种字符转换
    vc2008 访问C# WebService
    ZendStudio WSDL编辑器
    Nusoap复杂对象的的webService制作
  • 原文地址:https://www.cnblogs.com/jiasq/p/8604341.html
Copyright © 2011-2022 走看看