Spring配置文件详解 - applicationContext.xml文件路径
spring的配置文件applicationContext.xml的默认地址在WEB-INF下,只要在web.xml中加入代码
org.springframework.web.context.ContextLoaderListener
spring就会被自动加载
但在实际的开发过程中,我们可能需要调整applicationContext.xml的位置,以使程序结构更加的清晰。在web.xml中,配置Spring配置文件的代码如下:
contextConfigLocation这里写路劲
根据Spring框架的API描述,有以下四种方法配置applicationContext.xml文件路径
1. /WEB-INF/applicationContext.xml
2. com/config/applicationContext.xml
3. file:C:/javacode/springdemo/com/config/applicationContext.xml
4. classpath:com/config/applicationContext.xml
注:以上路径只是举例,具体使用还是要针对真是项目的,做编程的这点举一反三能力还是有的吧
开发过程中,如果spring的配置文件applicationContext.xml未加载的话,一般回报这样的错误 Could not open ServletContext resource [/WEB-INF/applicationContext.xml] 下面就有我为大家举例自定义applicationContext.xml路径的常见的方法。
1、Spring配置文件在WEB-INF下面

这种情况你可以不去管他,不进行配置,因为spring会默认去加载,如果一定要配置呢,可以这样
contextConfigLocationWEB-INF/applicationContext.xml
2、Spring配置文件在WEB-INF下的某个文件夹下,比如config下,可以这样配置

contextConfigLocationWEB-INF/config/applicationContext.xml
3、Spring配置文件在src下面,可以这样配置

contextConfigLocationWEB-INF/classes/applicationContext.xml
或者
contextConfigLocationclasspath:applicationContext.xml
4、Spring配置文件在src下的某个包里,比如com.config,可以这样配置

contextConfigLocationWEB-INF/classes/com/config/applicationContext.xml
或者
contextConfigLocationclasspath:com/config/applicationContext.xml
Spring配置文件详解 - applicationContext.xml文件路径的更多相关文章
- Spring配置文件详解 – applicationContext.xml文件路径
Spring配置文件详解 – applicationContext.xml文件路径 Java编程 spring的配置文件applicationContext.xml的默 ...
- spring配置文件详解--真的蛮详细
spring配置文件详解--真的蛮详细 转自: http://book.51cto.com/art/201004/193743.htm 此处详细的为我们讲解了spring2.5的实现原理,感觉非常 ...
- J2EE进阶(四)Spring配置文件详解
J2EE进阶(四)Spring配置文件详解 前言 Spring配置文件是用于指导Spring工厂进行Bean生产.依赖关系注入(装配)及Bean实例分发的"图纸".Java EE程 ...
- Spring中加载ApplicationContext.xml文件的方式
Spring中加载ApplicationContext.xml文件的方式 原文:http://blog.csdn.net/snowjlz/article/details/8158560 1.利用Cla ...
- [转载]Spring配置文件详解一:
原文地址:与base-package="com.xx">Spring配置文件详解一:<context:annotation-config/>与<contex ...
- spring配置文件详解以及beans:beans标签
第一行的意思就是你这个文件的默认schema为security,所以你的beans定义就需要加上前缀beans 一般的定义文件默认都是beans: 下面是spring配置文件的详解: 转自:http: ...
- Spring配置文件详解
转自: http://book.51cto.com/art/201004/193743.htm 此处详细的为我们讲解了spring2.5的实现原理,感觉非常有用 spring配置文件是用于指导Sp ...
- Spring 配置文件详解 (以2.5为例)
转载自:http://blog.csdn.net/zzjjiandan/article/details/22922847 Spring配置文件是用于指导Spring工厂进行Bean生 ...
- Spring学习总结(3)——Spring配置文件详解
Spring配置文件是用于指导Spring工厂进行Bean生产.依赖关系注入(装配)及Bean实例分发的"图纸".Java EE程序员必须学会并灵活应用这份"图纸&quo ...
随机推荐
- XP 安装不了framework 4.0 的解决方法
第一步: 如果是XP系统: 1.开始——运行——输入cmd——回车——在打开的窗口中输入net stop WuAuServ 2.开始——运行——输入%windir% 3.在打开的窗口中有个文件夹叫So ...
- 高斯过程(gaussian process)
Definition 1. A Gaussian Process is a collection of random variables, any finite number of which hav ...
- 利用Volley封装好的图片缓存处理加载图片
Volley 工具箱中提供了一种通过 DiskBasedCache 类实现的标准缓存.这个类能够缓存文件到磁盘的指定目录.但是为了使用 ImageLoader,我们应该提供一个自定义的内存 LRC b ...
- visual studio code 安装python扩展
Ctrl+P 调出控制台,在控制台里输入ext install python,点击第一个安装 如果出现: visual studio code connect ETIMEDOUT 191.238.17 ...
- ICEM相关
1,几何体建模不用讲(可以不学,因为通常是其他软件导入)在初始分块前,建立part,为建立边界条件使用(这是部分的定义最重要的作用,所以你可以按照不同的情况来定义,划分网格只是块的工作),所以对于三维 ...
- Devexpress DateEdit控件的值不反馈到数据源的处理方式。
如果在GridControl中要把编辑的值反馈到数据源,可以用Gridview1.PostEdit()方法. 可是在datalayout中使用就会遇到一些问题:比如说DateEdit控件,在保存数据的 ...
- The guard was taken to hospital in a critical condition.
The Prince George's County Fire Department said the guard was taken to hospital in a critical condit ...
- It will affect staff as well.
Premier Foods has reduced its number of suppliers dramatically in the last 12 months. In 2013 it mad ...
- js回车动态添加表格,右键动态删除表格行
<script type="text/javascript" language="javascript">//屏蔽浏览器右键function sto ...
- String类常用方法小节
(1)String.equals() 返回值是boolean类型 equals(Object anObject) 将此字符串与指定的对象比较. (2)length() 返回值是in ...