applicationContext.xml 配置文件的一些认识
存放位置:
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>
spring的 配置文件在启动时,加载的是web-inf目录下的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>
存放位置:
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>
spring的 配置文件在启动时,加载的是web-inf目录下的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 Controller单例陷阱
2014-09-12 10:01 927Spring MVC Controller默认是单例的: 单 ... -
Spring MVC模型(Model)层和视图(View)层
2014-04-20 18:57 0Spring MCV中Model层是View层的数据容器,Js ... -
springMVC 返回类型选择 以及 SpringMVC中model,modelMap.request,session取值顺序
2014-04-20 18:52 3069spring mvc处理方法支持如下的返回方式:ModelAn ... -
spring mvc常用注解@Component @Controller @Service @Repository
2014-03-13 16:10 9182注解用了之后,会在*.xml文件中大大减少配置量。以前我们每个 ... -
SpringMVC和Struts2的比较
2014-02-27 19:12 748通俗说Spring的作用 Spring ... -
Struts-config.xml配置文件《action-mappings》元素的详解
2014-02-26 13:12 2448action-mappings 该元素用于将Action元素定 ... -
使用Hibernate向mysql数据库中插入中文,数据库中显示??乱码
2014-02-24 23:02 1015[size=medium]通过网上学习,要求修改Hiberna ... -
在web.xml中通过contextConfigLocation配置spring
2014-02-24 21:19 2317在web.xml中通过contextConfigLocatio ... -
Struts-config.xml配置action-mappings元素略计
2014-02-24 16:58 636action-mappings 该元素用于将Action元素 ... -
Spring的DataAccessException略记
2013-07-08 19:23 2458Spring的DAO框架没有抛出 ... -
Result Type(Struts.xml配置)
2013-06-25 08:35 624一个提交到服务器的处理通常可以分为两个阶段: 第一个阶段查询服 ... -
ibatis常用标记略记
2013-06-23 21:12 972isNull判断property字段是否是null,用isEm ... -
ibatis的iterate使用
2013-06-23 20:38 1087ibatis的iterate使用 Iterate:这属性遍历 ... -
Struts2 两个Action之间动态传参
2013-06-21 10:00 1049两个Action 动态传参数 研究了近两天的时间 ... -
spring入门之—第一步
2013-06-13 15:26 723注: 本文用的是spring-framework-3.1.1. ... -
Spring的ApplicationContext加载多个配置文件的三种方式
2013-06-13 15:09 18291.第一种,使用数组方式 ApplicationConte ... -
详解iBaits中SqlMapClientTemplate的使用
2013-06-05 16:07 0pache iBatis(现已迁至Google Code下发展 ... -
Struts2.0默认支持多种格式的result type
2013-06-05 16:00 859<action name="attachmen ... -
maven+ssi对oracle实现增删改查(二)
2013-06-05 12:06 12001.index.jsp访问项目默认页面 <%@ page ... -
maven+ssi对oracle实现增删改查(一)
2013-06-05 11:40 1230-. 1.Oracle10g 的表结构语句,需要内容的自己添加 ...
相关推荐
applicationContext.xml 详细配置
struts.xml和applicationContext.xml、web.xml的配置
这是一些配置文件,可以作为参考,个人感觉很方便的学习方法
Spring Boot技术知识点:如何读取不同路径里的applicationContext.xml配置文件4
ssh框架事务管理applicationContext.xml配置文件
Spring applicationContext.xml常见部分属性的使用备注
SSH框架applicationContext.xml头部文件
本篇文章主要介绍了详解spring applicationContext.xml 配置文件 ,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
applicationContext.xml详解
包含applicationContext.xml、db.properties、log4j.properties、spring-mvc.xml文件,方便搭建,省去写代码。。
国际物流云商项目server_web子工程中的applicationContext.xml配置文件。
spring4的“所有jar包”+applicationContext.xml+web.xml====全套
Spring Boot技术知识点:如何读取不同路径里的applicationContext.xml配置文件6
Spring Boot技术知识点:如何读取不同路径里的applicationContext.xml配置文件1
在SSH的applicationContext.xml 中如何配制配制事务
Spring Boot技术知识点:如何读取不同路径里的applicationContext.xml配置文件
Spring Boot技术知识点:如何读取不同路径里的applicationContext.xml配置文件3
Spring Boot技术知识点:如何读取不同路径里的applicationContext.xml配置文件5
详解Spring的applicationContext.xml文件代码: