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"/>
  • 相关阅读:
    【poj2828】Buy Tickets
    【hdu2795】Billboard
    【hdu1394】Minimum Inversion Number
    【BZOJ1012】 【JSOI2008】最大数maxnumber
    【hdu】p1754I Hate It
    【线段树模板】
    Day1
    synchronized底层原理
    Java之浅拷贝和深拷贝
    图解算法——恢复一棵二叉搜索树(BST)
  • 原文地址:https://www.cnblogs.com/jiasq/p/8604341.html
Copyright © 2011-2022 走看看