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>
分享到:
相关推荐
spring-mvc.xml spring-mybatis.xml web.xml log4j.properties,项目中需要用到的配置文件。直接可用。
spring无web.xml零配置,使用javaconfig来进行spring配置,本项目使用maven管理,
spring在web.xml中和在struts中的不同配置..pdf
本篇文章主要介绍了Spring mvc的web.xml配置说明,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
加载spring 文件,在web.xml中的配置
springMVC零配置,无web.xml,无spring配置,纯java
主要介绍了Spring在web.xml中的配置详细介绍的相关资料,需要的朋友可以参考下
SpringMVC基于代码的配置方式(零配置,无web.xml) 本资源博客地址:http://blog.csdn.net/u013816347/
这份文件 把javaEE 中web.xml中的基本配置都 写在里面了
<param-value>/WEB-INF/spring-config.xml <!-- 备注:此所设定的参数,在JSP网页中可以使用下列方法来取得:${initParam.param_name} 若在Servlet可以使用下列方法来获得:String param_name=getServletContext...
在web.xml中配置spring容器的监听器。 2:项目集成springmvc 在web.xml中配置前端控制器 3:项目集成shiro 在web.xml中配置shiro过滤器 4:项目post乱码处理 在web.xml中配置字符过滤器 5:项目运行...
spring4的“所有jar包”+applicationContext.xml+web.xml====全套
NULL 博文链接:https://200cc.iteye.com/blog/2192843
spring无web.xml的jdbctemplate配置
java servlet spring web filter listenr
ssm一个简单项目所需的xml配置文件,spring+springmvc+mybatis框架中用到了三个XML配置文件:web.xml,spring-mvc.xml,spring-mybatis.xml.第一个不用说,每个web项目都会有的也是关联整个项目的配置.第二个文件spring-...
ssm整合步骤: 第一步:mybatis单独测试 1.引入mybatis,mysql依赖 2....注意:dao层只有接口。 3.创建dao层与之对象的mapper.xml配置文件 4.... 5.... 整合的思想:使用spring的ioc...在web.xml中配置spring的监听器即可。
利用jetty9启动无web.xml配置的spring4最简单应用程序 Requirements 启动应用程序的方法 方法1 mvn jetty:run 方法2 mvn clean install exec:exec 方法3 通过jetty的 org.eclipse.jetty.xml.XmlConfiguration 执行...
web应用程序通过Tomcat等容器启动时,会首先加载web.xml文件,通常我们工程中的各种配置文件,如日志、数据库、spring的文件等都在此时被加载,下面是两种常用的配置文件加载路径,即配置文件可以放到 SRC目录下或者...
- dataAccessContext-local/jta.xml (see web.xml's "contextConfigLocation"). --> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...