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 ...
随机推荐
- POJ 2229 Sumsets
Sumsets Time Limit: 2000MS Memory Limit: 200000K Total Submissions: 11892 Accepted: 4782 Descrip ...
- android 打包失败
如果在打包时提示: proguard returned with error code 1 并且在控制台中输出:'java'不是内部或外部程序或批处理文件 那么就说明你的环境变量出问题了,之前用的 ...
- java堆栈区别
/*java程序在运行时,jvm把内存分为5块,栈,堆,方法区,本地方法区,寄存器 栈:存储的是局部变量,在函数语句中定义的变量都是局部变量 for(int i=1;i<=5;i++){} ad ...
- ubuntu关于apache服务命令
一.Start Apache 2 Server /启动apache服务 # /etc/init.d/apache2 startor$ sudo /etc/init.d/apache2 start 二. ...
- sql高级语句大全
经典SQL语句大全 一.基础 1.说明:创建数据库 CREATE DATABASE database-name 2.说明:删除数据库 drop database dbname 3.说明:备份sql s ...
- Titanium studio安装
在Win7 Titanium Studio的安装过程. 1.准备工作 Titanium存储空间的要求,Titanium Studio 需要1 GB.Android SDK需要1.5 GB.Blackb ...
- 【kate整理】matlab求商,求余数
a/b=q...r a=b*q+r r为余数 fix(a/b) 求商rem(a,b) 求余数还可以 mod(a,b) 两者的区别是余数的符号,rem与a相同,而mod与b相同 例1: & ...
- 使用命令行工具运行Xcode 7 UI Tests
原文:Run Xcode 7 UI Tests from the command line 苹果在Xcode 7中引入了一项新技术UI Tests,允许开发者使用Swift或Objective C代码 ...
- C#打印条码与ZPL
ZPL(Zebra Programming Language) 是斑马公司(做条码打印机的公司)自己设计的语言, 由于斑马打印机是如此普遍, 以至于据我所见所知, 条码打印机全部都是斑马的, 所以控制 ...
- Linux内核分析—完成一个简单的时间片轮转多道程序内核代码
---恢复内容开始--- 20135125陈智威 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-10 ...