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. Silverlight js html 相互调用

    1.sl调用js 比如我们在页面中定义一个js函数: <script type="text/javascript">        function fnTest(ms ...

  2. Unity有限状态机编写

    有限状态机FSM 是对行为逻辑的抽象. 在整个FSM架构中 首先有一个状态基类stateObject 里面有三个方法,分别是状态前.状态中.状态后. 所有具体行为类都要继承这个基类,在这三个方法中具体 ...

  3. iOS: 消息通信中的Notification&KVO

    iOS: 消息通信中的Notification&KVO 在 iOS: MVC 中,我贴了张经典图: 其中的Model向Controller通信的Noification&KVO为何物呢? ...

  4. C语言中的系统时间结构体类型

    在C语言涉及中经常需要定时触发事件,涉及到获取系统时间,其结构体类型有多种.Unix/Linux系统下有以下几种时间结构: 1.time_t 类型:长整型,一般用来表示从1970-01-01 00:0 ...

  5. 磁盘IO性能监控(Linux 和 Windows)

    磁盘IO性能监控(Linux 和 Windows) 作者:终南   <li.zhongnan@hotmail.com> 磁盘的IO性能是衡量计算机总体性能的一个重要指标.Linux提供了i ...

  6. BZOJ 2298 problem a(区间DP)

    题意:一次考试共有n个人参加,第i个人说:“有ai个人分数比我高,bi个人分数比我低.”问最少有几个人没有说真话(可能有相同的分数) 思路:考虑最多有多少人说真,那么答案就是n-max. ai个人分数 ...

  7. 《Programming WPF》翻译 第5章 2.内嵌样式

    原文:<Programming WPF>翻译 第5章 2.内嵌样式 每一个“可样式化”的WPF元素都有一个Style属性,可以在内部设置这个属性--使用XAML属性-元素的语法(在第一章讨 ...

  8. 把C#程序(含多个Dll)合并打包成单一文件

    实现的方式有多种. 1 Mono 项目中有一个工具,mono的一个附属工具mkbundle.(在Xamarin未被收购开源前,它是加密的商业软件.http://www.cnblogs.com/bins ...

  9. Linux上ld和ld.so命令的区别

    显然,ld链接器,它的生命周期是发生在compile-time的,它的一些参数是编译时期gcc给传递的,比如,指定需要链接什么库. ld.so命令的周期是发生在run-time的,名字叫动态链接器/加 ...

  10. Android 图片合成:添加蒙板效果 不规则相框 透明度渐变效果的实现

    Android 图片合成:添加蒙板效果 不规则相框 透明度渐变效果的实现 暂时还未有时间开发这效果,所以先贴出来. 先贴一张效果图,这是一张手机截屏: 左上方的风景图:背景图片 右上方的人物图:前景图 ...