1, 在web.xml中定义 contextConfigLocation参数.spring会使用这个参数加载.所有逗号分割的xml.如果没有这个参数,spring默认加载web-inf/applicationContext.xml文件

<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>
    classpath*:conf/spring/applicationContext_core*.xml,
    classpath*:conf/spring/applicationContext_dict*.xml,
    classpath*:conf/spring/applicationContext_hibernate.xml,
    classpath*:conf/spring/applicationContext_staff*.xml,
    classpath*:conf/spring/applicationContext_security.xml
    classpath*:conf/spring/applicationContext_modules*.xml
    classpath*:conf/spring/applicationContext_cti*.xml
    classpath*:conf/spring/applicationContext_apm*.xml
  </param-value>
</context-param>

contextConfigLocation 参数定义了要装入的 Spring 配置文件。原理说明如下:
、利用ServletContextListener 实现。
Spring 提供ServletContextListener 的一个实现类ContextLoaderListener ,该类可以作
为listener 使用,它会在创建时自动查找WEB-INF/ 下的applicationContext.xrnl 文件。因
此,如果只有一个配置文件,并且文件名为applicationContext.xml ,则只需在web.xml
文件中增加如下代码即可:

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

如果有多个配置文件需要载入,则考虑使用<context-para即元素来确定配置文件的
文件名。由于ContextLoaderListener加载时,会查找名为contextConfigLocation的参数。
因此,配置context-param时参数名字应该是contextConfigLocation。
带多个配置文件的web.xml 文件如下

<!-- XML 文件的文件头--〉
<?xml version="l.O" encoding="工80-8859-1"?>
<!-- web.xm1 文件的DTD 等信息--〉
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems. 工口c.//DTD Web Application 2.3//EN"
''http://java.sun.com/dtd/web-app_2_3.dtd''>
<web-app>
<!--确定多个配置文件-->
<context-param>
<!-- 参数名为contextConfigLocation…--〉
<param-name>contextConfigLocation</param-name>
<!一多个配置文件之间以,隔开--〉
<param-value>
/WEB-INF/daoContext.xml,
/WEB-INF/applicationContext.xml</param-value>
</context-param>
<!-- 采用listener创建Applicat工onContext 实例-->
<listener>
<listener-class>org.spr工ngframework.web.context.ContextLoader
Listener</listener-class>
</listener>
</web-app>

spring 在web.xml 里面如何使用多个xml配置文件的更多相关文章

  1. J2EE进阶(五)Spring在web.xml中的配置

     J2EE进阶(五)Spring在web.xml中的配置 前言 在实际项目中spring的配置文件applicationcontext.xml是通过spring提供的加载机制自动加载到容器中.在web ...

  2. 使用Spring时web.xml中的配置

    使用Spring时web.xml中的配置: <?xml version="1.0" encoding="UTF-8"?> <web-app x ...

  3. Spring 入门 web.xml配置详解

    Spring 入门 web.xml配置详解 https://www.cnblogs.com/cczz_11/p/4363314.html https://blog.csdn.net/hellolove ...

  4. spring在web.xml中的配置

    在实际项目中spring的配置文件applicationcontext.xml是通过spring提供的加载机制,自动加载的容器中去,在web项目中,配置文件加载到web容器中进行解析,目前,sprin ...

  5. spring 的web.xml

    <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java ...

  6. Spring的web应用启动加载数据字典方法

    在一个基于Spring的web项目中,当我们需要在应用启动时加载数据字典时,可写一个监听实现javax.servlet.ServletContextListener 实现其中的contextIniti ...

  7. Spring实战5:基于Spring构建Web应用

    主要内容 将web请求映射到Spring控制器 绑定form参数 验证表单提交的参数 对于很多Java程序员来说,他们的主要工作就是开发Web应用,如果你也在做这样的工作,那么你一定会了解到构建这类系 ...

  8. 使用XFire+Spring构建Web Service(一)——helloWorld篇

    转自:http://www.blogjava.net/amigoxie/archive/2007/09/26/148207.html原文出处:http://tech.it168.com/j/2007- ...

  9. 使用Maven创建一个Spring MVC Web 项目

    使用Maven创建java web 项目(Spring MVC)用到如下工具: 1.Maven 3.2 2.IntelliJ IDEA 13 3.JDK 1.7 4.Spring 4.1.1 rele ...

随机推荐

  1. Canvas学习:封装Canvas绘制基本图形API

    Canvas学习:封装Canvas绘制基本图形API Canvas Canvas学习   从前面的文章中我们了解到,通过Canvas中的CanvasRenderingContext2D对象中的属性和方 ...

  2. 使用Statement执行DML和DQL语句

    import com.loaderman.util.JdbcUtil; import java.sql.Connection; import java.sql.DriverManager; impor ...

  3. 判断是否为日期格式 与 判断是否为BigDecimal

    import java.text.ParseException;import java.text.SimpleDateFormat; /** * * 说明:判断是否为日期格式 * @param str ...

  4. SQLite 版本引发的 Python 程序调用问题

    问题 在跑 OpenStack functional 功能测试的时候有两个用例过不去. nova.tests.functional.db.test_resource_provider.Resource ...

  5. redis(3)主从与集群

    一.主从架构 yum安装的redis cd /etc/ cp redis.conf /etc/slave.conf vim slave.conf bind 192.168.42.7 slaveof p ...

  6. Spring JdbcTemplate实例

    1.常用方法 * update():执行DML语句.增.删.改语句* queryForMap():查询结果将结果集封装为map集合,将列名作为key,将值作为value 将这条记录封装为一个map集合 ...

  7. EF Code First 学习笔记:约定配置 Data Annotations+Fluent API

    要更改EF中的默认配置有两个方法,一个是用Data Annotations(在命名空间System.ComponentModel.DataAnnotations;),直接作用于类的属性上面;还有一个就 ...

  8. django中的urlpatterns的正则语法

    ^ 指定起始字符或字符串,放进[]代表否定 $ 指定终止字符 / 对应原来的字符 [...] 括号中表示一个字符的格式设置 \d 任何一个数字字符 \D 非数字的字符 \w 任何一个字符[a-zA-Z ...

  9. gin框架教程:代码系列demo地址

    gin框架教程代码地址: https://github.com/jiujuan/gin-tutorial demo目录: 01quickstart 02parameter 03route 04midd ...

  10. 03-MySQL多表操作

    一.表之间的关系 1.如何找出两张表之间的关系 分析步骤: #.先站在左表的角度去找 是否左表的多条记录可以对应右表的一条记录,如果是,则证明左表的一个字段foreign key 右表一个字段(通常是 ...