web.xml 通过contextConfigLocation配spring 的方式
来源:互联网 发布:时间管理的软件 编辑:程序博客网 时间:2024/06/01 23:22
web.xml 通过contextconfiglocation配置spring 的方式
ssi框架配置文件路径问题:
struts2的 1个+n个 路径:src+src(可配置) 名称: struts.xml + n
spring 的 1个 路径: src 名称: applicationcontext.xml
ibatis 的 1个+n个 路径: src+src(可配置) 名称: sqlmapconfig.xml + n
部署到tomcat后,src目录下的配置文件会和class文件一样,自动copy到应用的 classes目录下
spring的 配置文件在启动时,加载的是web-info目录下的applicationcontext.xml,
运行时使用的是web-info/classes目录下的applicationcontext.xml。
配置web.xml使这2个路径一致:
<context-param>
<param-name>contextconfiglocation</param-name>
<param-value>/web-inf/classes/applicationcontext.xml</param-value>
</context-param>
多个配置文件的加载,以逗号隔开
<context-param>
<param-name>contextconfiglocation</param-name>
<param-value>
classpath*:conf/spring/applicationcontext_core*.xml,
classpath*:conf/spring/applicationcontext_dict*.xml,
classpath*:conf/spring/applicationcontext_hibernate.xml,
classpath*:conf/spring/applicationcontext_staff*.xml,
classpath*:conf/spring/applicationcontext_security.xml
classpath*:conf/spring/applicationcontext_modules*.xml,
classpath*:conf/spring/applicationcontext_cti*.xml,
classpath*:conf/spring/applicationcontext_apm*.xml
</param-value>
</context-param>
contextconfiglocation 参数定义了要装入的 spring 配置文件。
首先与spring相关的配置文件必须要以"applicationcontext-"开头,要符合约定优于配置的思想,这样在效率上和出错率上都要好很多。
还有最好把所有spring配置文件都放在一个统一的目录下,如果项目大了还可以在该目录下分模块建目录。这样程序看起来不会很乱。
在web.xml中的配置如下:
xml代码
<context-param>
<param-name>contextconfiglocation</param-name>
<param-value>classpath*:**/applicationcontext-*.xml</param-value>
</context-param>
"**/"表示的是任意目录;
"**/applicationcontext-*.xml"表示任意目录下的以"applicationcontext-"开头的xml文件。
你自己可以根据需要修改。最好把所有spring配置文件都放在一个统一的目录下,如:
<!-- spring 的配置 -->
<context-param>
<param-name>contextconfiglocation</param-name>
<param-value>classpath:/spring/applicationcontext-*.xml</param-value>
</context-param>
web.xml中classpath:和classpath*:, 有什么区别?
classpath:只会到你的class路径中查找找文件;
classpath*:不仅包含class路径,还包括jar文件中(class路径)进行查找.
ssi框架配置文件路径问题:
struts2的 1个+n个 路径:src+src(可配置) 名称: struts.xml + n
spring 的 1个 路径: src 名称: applicationcontext.xml
ibatis 的 1个+n个 路径: src+src(可配置) 名称: sqlmapconfig.xml + n
部署到tomcat后,src目录下的配置文件会和class文件一样,自动copy到应用的 classes目录下
spring的 配置文件在启动时,加载的是web-info目录下的applicationcontext.xml,
运行时使用的是web-info/classes目录下的applicationcontext.xml。
配置web.xml使这2个路径一致:
<context-param>
<param-name>contextconfiglocation</param-name>
<param-value>/web-inf/classes/applicationcontext.xml</param-value>
</context-param>
多个配置文件的加载,以逗号隔开
<context-param>
<param-name>contextconfiglocation</param-name>
<param-value>
classpath*:conf/spring/applicationcontext_core*.xml,
classpath*:conf/spring/applicationcontext_dict*.xml,
classpath*:conf/spring/applicationcontext_hibernate.xml,
classpath*:conf/spring/applicationcontext_staff*.xml,
classpath*:conf/spring/applicationcontext_security.xml
classpath*:conf/spring/applicationcontext_modules*.xml,
classpath*:conf/spring/applicationcontext_cti*.xml,
classpath*:conf/spring/applicationcontext_apm*.xml
</param-value>
</context-param>
contextconfiglocation 参数定义了要装入的 spring 配置文件。
首先与spring相关的配置文件必须要以"applicationcontext-"开头,要符合约定优于配置的思想,这样在效率上和出错率上都要好很多。
还有最好把所有spring配置文件都放在一个统一的目录下,如果项目大了还可以在该目录下分模块建目录。这样程序看起来不会很乱。
在web.xml中的配置如下:
xml代码
<context-param>
<param-name>contextconfiglocation</param-name>
<param-value>classpath*:**/applicationcontext-*.xml</param-value>
</context-param>
"**/"表示的是任意目录;
"**/applicationcontext-*.xml"表示任意目录下的以"applicationcontext-"开头的xml文件。
你自己可以根据需要修改。最好把所有spring配置文件都放在一个统一的目录下,如:
<!-- spring 的配置 -->
<context-param>
<param-name>contextconfiglocation</param-name>
<param-value>classpath:/spring/applicationcontext-*.xml</param-value>
</context-param>
web.xml中classpath:和classpath*:, 有什么区别?
classpath:只会到你的class路径中查找找文件;
classpath*:不仅包含class路径,还包括jar文件中(class路径)进行查找.
0 0
- web.xml 通过 contextConfigLocation 配 spring 方式
- web.xml 通过contextConfigLocation配spring 的方式
- web.xml 通过contextConfigLocation配spring 的方式
- web.xml 通过contextConfigLocation配spring 的方式
- web.xml 通过contextConfigLocation配置spring 的方式
- web.xml 通过contextConfigLocation配置spring 的方式
- web.xml 通过contextConfigLocation配置spring 的方式
- web.xml 通过contextConfigLocation配置spring 的方式(转)
- 通过contextConfigLocation配spring的方式
- 在web.xml中通过contextConfigLocation配置spring
- 学Spring之web.xml中的contextConfigLocation的作用
- web.xml的contextConfigLocation通过文件名模糊匹配加载多个xml文件的技巧
- web.xml中的contextConfigLocation的作用
- web.xml中contextConfigLocation的作用
- web.xml中的contextConfigLocation的作用
- web.xml中的contextConfigLocation的作用
- web.xml中contextConfigLocation参数的作用
- web.xml中的contextConfigLocation的作用
- 斯坦福数据挖掘不同版本课件讲局部敏感哈希中MinHash的理解
- 字符串匹配的KMP算法
- VS2010输出标准信息(stdout)到output窗口
- MFC——属性页对话框的创建
- 黑马程序员—Java基础—IO4
- web.xml 通过contextConfigLocation配spring 的方式
- win7/9/10 U盘启动盘的制作
- uiautomator使用
- 可拖动的圆形进度条
- EM-期望最大化算法
- 10001---JavaWeb开发基础--初识Tomcat
- 数据库水平切分的实现原理解析
- diy高手在民间
- 计数排序算法之Java实现