Spring配置文件详解 – applicationContext.xml文件路径
Spring配置文件详解 – applicationContext.xml文件路径
spring的配置文件applicationContext.xml的默认地址在WEB-INF下,只要在web.xml中加入代码
|
1
2
3
4
5
|
<listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener> |
spring就会被自动加载
但在实际的开发过程中,我们可能需要调整applicationContext.xml的位置,以使程序结构更加的清晰。在web.xml中,配置Spring配置文件的代码如下:
|
1
2
3
4
|
<context-param><param-name>contextConfigLocation</param-name><param-value>这里写路劲</param-value></context-param> |
根据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会默认去加载,如果一定要配置呢,可以这样
|
1
2
3
4
|
<context-param><param-name>contextConfigLocation</param-name><param-value>WEB-INF/applicationContext.xml</param-value></context-param> |
2、Spring配置文件在WEB-INF下的某个文件夹下,比如config下,可以这样配置 
|
1
2
3
4
|
<context-param><param-name>contextConfigLocation</param-name><param-value>WEB-INF/config/applicationContext.xml</param-value></context-param> |
3、Spring配置文件在src下面,可以这样配置 
|
1
2
3
4
|
<init-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></-param> |
或者
|
1
2
3
4
|
<context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param> |
4、Spring配置文件在src下的某个包里,比如com.config,可以这样配置 
|
1
2
3
4
|
<context-param><param-name>contextConfigLocation</param-name><param-value>WEB-INF/classes/com/config/applicationContext.xml</param-value></context-param> |
或者
|
1
2
3
4
|
<context-param><param-name>contextConfigLocation</param-name><param-value>classpath:com/config/applicationContext.xml</param-value></context-param> |
Spring配置文件详解 – applicationContext.xml文件路径的更多相关文章
- Spring配置文件详解 - applicationContext.xml文件路径
spring的配置文件applicationContext.xml的默认地址在WEB-INF下,只要在web.xml中加入代码 org.springframework.web.context.Cont ...
- 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 ...
随机推荐
- shell正则表达式(zhuan)
匹配中文字符的正则表达式:[u4e00-u9fa5] 评注:匹配中文还真是个头疼的事,有了这个表达式就好办了 匹配双字节字符(包括汉字在内):[^x00-xff] 评注:可以用来计算字符串的长度(一个 ...
- android开发------编写用户界面之线性布局
一个好的应用程序离不开人性化的用户界面.在学习其他东西之前.理应先学习编写程序的布局(外观) 今天,我们就来学习android的UI布局----LinearLayout. LinearLayout,即 ...
- Day One(Beta)
站立式会议 站立式会议内容总结 331 今天:自己摸索了BaseAdapter删除元素的三种方式更新效率逐步上升 明天:学习webkit的webview的使用 442 今天:书籍评价界面,计划删除功能 ...
- iOS常用---NSString,NSMutabuleString
普通的创建字符串: NSString *string =[[NSString alloc]init]; //创建一个空的字符串,即 @“” 一 .字符串读取本地文件: 参数一: 文件地址 参数二: 文 ...
- iPad开发--QQ空间布局,登录模块
一.登录模块 登录逻辑 - (IBAction)loginClick:(UIButton *)sender { self.view.userInteractionEnabled = NO; [self ...
- 【BZOJ 4547】【HDU 5157】小奇的集合
http://www.lydsy.com/JudgeOnline/problem.php?id=4547 本蒟蒻并不会矩乘求Fibonacci数列前缀和,所以果断分块打表,常数竟然比矩乘要小! PS: ...
- 【BZOJ 2599】【IOI 2011】Race 点分治
裸的点分治,然而我因为循环赋值$s$时把$i <= k$写成$i <= n$了,WA了好长时间 #include<cstdio> #include<cstring> ...
- 上传文件到hdfs注意事项
我在MapReduceInput下创建CFItemSet文件夹,下面有itemSet.txt. 我想上传到cf下,然后想着hdfs上会显示cf/itemSet.txt. hdfs dfs -put i ...
- oracle merge into 的例子
内容来自 oracle 11g 实用教程 郑阿奇等编 在 oracle 11g中有merge语句,用于根据与原表连接的结果,对目标表执行插入,更新,或者删除操作.例如,根据在一个表中找到的差异在另一个 ...
- 【uoj149】 NOIP2015—子串
http://uoj.ac/problem/149 (题目链接) 题意 给出两个字符串A.B,问从A中取出k个互不重叠的子串按顺序组成B的方案数. Solution 一看这种题目就是字符串dp,字符串 ...