web.xml中配置applicationContext.xml 配置文件的存放位置
classpath:只会到你的class路径中查找找文件;
classpath*:不仅包含class路径,还包括jar文件中(class路径)进行查找.
二、存放位置:
1:src下面
需要在web.xml中定义如下:
1234<
context-param
>
<
param-name
>contextConfigLocation</
param-name
>
<
param-value
>classpath:applicationContext.xml</
param-value
>
< /
context-param
>
2:WEB-INF下面
需要在web.xml中定义如下:
1234<
context-param
>
<
param-name
>contextConfigLocation</
param-name
>
<
param-value
>WEB-INF/applicationContext*.xml</
param-value
>
< /
context-param
>
3、contextConfigLocation参数定义了要装入的Spring配置文件。
首先与Spring相关的配置文件必须要以"applicationContext-"开头,要符合约定优于配置的思想,这样在效率上和出错率上都要好很多。
还有最好把所有Spring配置文件都放在一个统一的目录下,如果项目大了还可以在该目录下分模块建目录。这样程序看起来不会很乱。
在web.xml中的配置如下:
Xml代码
1234<
context-param
>
<
param-name
>contextConfigLocation</
param-name
>
<
param-value
>classpath*:**/applicationContext-*.xml</
param-value
>
</
context-param
>
"**/"表示的是任意目录;
"**/applicationContext-*.xml"表示任意目录下的以"applicationContext-"开头的XML文件。
来自为知笔记(Wiz)
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。