2024年6月3日发(作者:)

竭诚为您提供优质文档/双击可除

模板

篇一:配置文件的存放位置

配置文件的存放位置web

.xml中classpath:和classpath*:有什么区别

classpath:只会到你的class路径中查找找文件;

classpath*:不仅包含class路径,还包括jar文件中

(class路径)进行查找.

存放位置:

1:src下面需要在中定义如下:

contextconfiglocation

classpath:

2:web-inF下面需要在中定义如下:

contextconfiglocation

web-inF/applicationcontext*.xml

1 6

通过contextconfiglocation配置spring的方

式ssi框架配置文件路径问题:

struts2的1个+n个路径:src+src(可配置)名称:

+nspring的1个路径:src名称:

tis的1个+n个路径:

src+src(可配置)名称:+n

部署到应用服务器(tomcat)后,src目录下的配置文件

会和class文件一样,自动copy到应用的classes目录下

spring的配置文件在启动时,加载的是web-info目录

下的,运行时使用的是

web-info/classes目录下的。配

置使这2个路径一致:

contextconfiglocation

/web-inF/classes/

多个配置文件的加载

contextconfiglocation

classpath*:conf/spring/applicationcontext_core*.xml,

2 6

classpath*:conf/spring/applicationcontext_dict*.xml,

classpath*:conf/spring/applicationcontext_hibernate

.xml

contextconfiglocation参数定义了要装入的spring配

置文件。

首先与spring相关的配置文件必须要以

"applicationcontext-"开头,

要符合约定优于配置的思想,这样在效率上和出错率上

都要好很多。

还有最好把所有spring配置文件都放在一个统一的目

录下,如果项目大了还可以在该目录下分模块建目录。

这样程序看起来不会很乱。

在中的配置如下:

xml代码

contextconfiglocation

classpath*:**/applicationcontext-*.xml

"**/"表示的是任意目录;

"**/applicationcontext-*.xml"表示任意目录下的以

3 6