博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
web.xml 配置 contextConfigLocation
阅读量:4216 次
发布时间:2019-05-26

本文共 2236 字,大约阅读时间需要 7 分钟。

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

classpath:只会到你的class路径中查找找文件; 

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

 有时候会用模糊匹配的方式配置多配置文件。

但是如果配置文件是在jar包里,模糊匹配就找不到了。可以用逗号隔开的方式配置多个配置文件。

如:

contextConfigLocation
classpath*:applicationContext.xml, classpath*:app-datasource.xml, classpath*:app-memcached.xml, classpath*:app-ibatis.xml, classpath*:app-rest.xml

存放位置:

1:src下面
需要在web.xml中定义如下:

contextConfigLocation
classpath:applicationContext.xml
< /context-param>

2:WEB-INF下面

需要在web.xml中定义如下:

contextConfigLocation
WEB-INF/applicationContext*.xml

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个路径一致: 

contextConfigLocation
/WEB-INF/classes/applicationContext.xml

多个配置文件的加载 

contextConfigLocation
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

contextConfigLocation 参数定义了要装入的 Spring 配置文件。 

首先与Spring相关的配置文件必须要以"applicationContext-"开头,要符合约定优于配置的思想,这样在效率上和出错率上都要好很多。 

还有最好把所有Spring配置文件都放在一个统一的目录下,如果项目大了还可以在该目录下分模块建目录。这样程序看起来不会很乱。 
在web.xml中的配置如下: 
Xml代码 

contextConfigLocation
classpath*:**/applicationContext-*.xml

"**/"表示的是任意目录; 

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

<!-- Spring 的配置 --> 

contextConfigLocation
classpath:/spring/applicationContext-*.xml

转载地址:http://xenmi.baihongyu.com/

你可能感兴趣的文章
iOS上如何让按钮文本左对齐问题
查看>>
Xcode8 兼容iOS 10 整理笔记
查看>>
iOS 枚举的巧用
查看>>
让你的 Xcode8 继续使用插件
查看>>
iOS去除导航栏和tabbar的1px横线
查看>>
iOS GitHub上常用第三方框架
查看>>
ios 隐藏cell分割线和自定义cell分割线颜色
查看>>
ios 图片保存到系统相册
查看>>
UIAlertController样式集合
查看>>
数据结构之—图
查看>>
计算机网络基础
查看>>
C++中内存(堆和栈)
查看>>
循环队列
查看>>
网络基础知识点总结1
查看>>
操作系统知识点总结1
查看>>
C++常见知识点总结
查看>>
Linux知识点小结One
查看>>
数据库知识点小结
查看>>
指针、内存和字节
查看>>
设计模式中类的关系
查看>>