eb.xml中classpath:和classpath*: 有什么不同?
classpath它只会降临到你身上。class在路径中查找文件。;
classpath*:不仅包含class路径,还包括jar文件中(class路径)进行查找.
存储位置:
1: **src 下面 需要在web.xml定义如下:**
contextConfigLocation
classpath:applicationContext.xml
< /context-param>
**2:WEB-INF下面 需要在web.xml定义如下** :
contextConfigLocation
WEB-INF/applicationContext*.xml
< /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路径一致:
contextConfigLocation
/WEB-INF/classes/applicationContext.xml
< /context-param>
加载多个配置文件
contextConfigLocation
classpath*:conf/spring/applicationContext\_core*.xml,
classpath*:conf/spring/applicationContext\_dict*.xml,
classpath*:conf/spring/applicationContext\_hibernate.xml
contextConfigLocation 参数定义 Spring 配置文件。
首先与Spring关联的配置文件必须是"applicationContext-"开头,
为了符合约定优于配置的理念,这在效率和错误率方面要好得多。
最好把所有Spring配置文件都放在统一的目录中。如果项目很大,还可以在此目录下的模块中构建目录。
这样程序看起来就不会乱糟糟了。
在web.xml中的配置如下:
Xml代码
< param-name>contextConfigLocation
< param-value>classpath*:**/applicationContext-*.xml
< /context-param>
"**/"表示任意目录;
"**/applicationContext-*.xml"表示任何目录"applicationContext-"开头的XML文件。
您可以根据需要自行修改。最好通吃Spring配置文件放置在统一目录中,例如:
contextConfigLocation
classpath:/spring/applicationContext-*.xml
< /context-param>
版权声明
所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除