web.xml中classpath:和classpath*:

 
 

IccBoY

applicationContext.xml 配置文件的存放位置

web.xml中classpath:和classpath*:  有什么区别?

classpath:只会到你的class路径中查找找文件; 
classpath*:不仅包含class路径,还包括jar文件中(class路径)进行查找.

存放位置:
1:src下面
需要在web.xml中定义如下:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
< /context-param>

2:WEB-INF下面
需要在web.xml中定义如下:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/applicationContext*.xml</param-value>
< /context-param>

web.xml 通过contextConfigLocation配置spring 的方式 
SSI框架配置文件路径问题:

struts2的 1个+N个 路径:src+src(可配置) 名称: struts.xml + N 
spring 的 1个 路径: src 名称: applicationContext.xml
ibatis 的 1个+N个 路径: src+src(可配置) 名称: SqlMapConfig.xml + N

部署到tomcat后,src目录下的配置文件会和class文件一样,自动copy到应用的 classes目录下

spring的 配置文件在启动时,加载的是web-info目录下的applicationContext.xml, 
运行时使用的是web-info/classes目录下的applicationContext.xml。

配置web.xml使这2个路径一致:

<context-param> 
<param-name>contextConfigLocation</param-name> 
<param-value>/WEB-INF/classes/applicationContext.xml</param-value> 
< /context-param>

多个配置文件的加载 
<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 配置文件。

首先与Spring相关的配置文件必须要以"applicationContext-"开头,要符合约定优于配置的思想,这样在效率上和出错率上都要好很多。 
还有最好把所有Spring配置文件都放在一个统一的目录下,如果项目大了还可以在该目录下分模块建目录。这样程序看起来不会很乱。 
在web.xml中的配置如下: 
Xml代码 
<context-param> 
< param-name>contextConfigLocation</param-name> 
< param-value>classpath*:**/applicationContext-*.xml</param-value> 
< /context-param>

"**/"表示的是任意目录; 
"**/applicationContext-*.xml"表示任意目录下的以"applicationContext-"开头的XML文件。 
你自己可以根据需要修改。最好把所有Spring配置文件都放在一个统一的目录下,如:

<!-- Spring 的配置 --> 
<context-param> 
<param-name>contextConfigLocation</param-name> 
<param-value>classpath:/spring/applicationContext-*.xml</param-value> 
< /context-param>

web.xml中classpath:和classpath*: 有什么区别?的更多相关文章

  1. 在web.xml中classpath和classpath*的区别

    classpath 和 classpath* 区别: classpath:只会到你指定的class路径中查找找文件; classpath*:不仅包含class路径,还包括jar文件中(class路径) ...

  2. Web.xml中自动扫描Spring的配置文件及resource时classpath*:与classpath:的区别

    Web.xml中自动扫描Spring的配置文件及resource时classpath*:与classpath:的区别 一.Web.xml中自动扫描Spring的配置文件(applicationCont ...

  3. web.xml中classpath 解释

    经过我在对 web.xml 的配置测试: web.xml 中classpath 所指的路径是项目工程路径下的 classes 文件夹

  4. web.xml中classpath*:与classpath:的区别

    classpath对应src目录,该目录下的文件会在编译后被存放到WEB-INF文件夹下的classes目录. classpath:只会到你的class路径中查找配置文件,对于多个同名的配置文件,只会 ...

  5. Spring MVC-从零开始-web.xml中classpath和classpath* 有什么区别

    web.xml中classpath和classpath* 有什么区别?classpath:只会到你的class路径中查找找文件;classpath*:不仅包含class路径,还包括jar文件中(cla ...

  6. web.xml中的classpath是啥

    在web.xml中一个很面熟的字:classpath,它到底是个啥? <servlet> <servlet-name>dispatcherServlet</servlet ...

  7. web.xml中的contextConfigLocation在spring中的作用

    在web.xml中通过contextConfigLocation配置spring, contextConfigLocation参数定义了要装入的 Spring 配置文件.默认会去/WEB-INF/下加 ...

  8. JavaEE web.xml 中ContextLoaderListener的解析

    ContextLoaderListener监听器的作用就是启动Web容器时,自动装配ApplicationContext的配置信息.因为它实现了ServletContextListener这个接口,在 ...

  9. web.xml中的contextConfigLocation的作用

    在web.xml中通过contextConfigLocation配置spring,contextConfigLocation 参数定义了要装入的 Spring 配置文件. 如果想装入多个配置文件,可以 ...

随机推荐

  1. 奇怪的JS正则表达式问题

    同一个正则表达式,为什么在JS里,用 var reg = new RegExp("..."); 定义,验证就各种失败,用 var reg=/.../; 定义,验证就对了...

  2. 第一个程序 - Windows程序设计(SDK)001

    愉快的开始 让编程改变世界 Change the world by program 编译器安装 我们经常说的 VS 指的就是 Microsoft Visual Studio 的简称,它是微软开发工具的 ...

  3. js给div动态添加控件,然后给这个控件动态添加事件

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx. ...

  4. 递归实现全排列序列C语言实现

    大家好,我是小鸭酱,博客地址为:http://www.cnblogs.com/xiaoyajiang 以下鄙人用递归回溯的办法,采用C语言实现了全排列序列,用以某些优化方案的原始方案的给定 #incl ...

  5. BZOJ 1977 次小生成树(最近公共祖先)

    题意:求一棵树的严格次小生成树,即权值严格大于最小生成树且权值最小的生成树. 先求最小生成树,对于每个不在树中的边,取两点间路径的信息,如果这条边的权值等于路径中的权值最大值,那就删掉路径中的次大值, ...

  6. 关于sencha touch 的JSONP跨域请求的学习研究

    此篇文章是对自己在研究学习sencha touch的过程中的点滴记录,主要是JSONP的跨域请求这方面,对于何为是跨域概念还有不熟悉的,可以自己问下度娘. 先上张图: 我要完成的功能就是表格下拉刷新, ...

  7. GBT28181中的RTP

    国标中说h264数据按照RFC3984打包,但是国标的测试工具——SPVMN,却不支持RFC3984的打包方式.无奈之下直接用RFC3550的方式打包,其实就是分包,然后加上RTP头,对于一帧的结束, ...

  8. Longest Valid Parentheses 解答

    Question Given a string containing just the characters '(' and ')', find the length of the longest v ...

  9. Android实现Live Photos 加源代码

    在Android手机上实现类似于iphone中的LivePhoto的功能 源代码分享 github:https://github.com/amazingyyc/DeepRed 代码说明: 1.改变视频 ...

  10. Android 之 Eclipse 导入 Android 源码

    很多人都下载过下图中的 Sources for Android SDK,但是很少人知道怎么用       下载完毕后可以再 Android SDK 根目录下看到 sources 文件夹内 有 andr ...