码迷,mamicode.com
首页 > 其他好文 > 详细

Struts2更改配置文件struts.xml默认路径

时间:2014-09-19 22:34:06      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:struts2   配置文件   struts.xml   

struts2配置文件默认存放路径在/WEB-INF/classes目录下,即将struts.xml放在src的目录下。

但是为了协作开发与方便管理,我们有时需要把struts.xml放到其他位置

struts2加载配置文件都是先从自己的jar包和/WEB-INF/classes两个默认的位置加载的。

若修改struts2配置文件的存放位置,在web.xml配置过虑器,具体配置如下:

<filter>
	<filter-name>struts2</filter-name>
	<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
	<init-param>
		<param-name>config</param-name>
		<param-value>struts-default.xml,struts-plugin.xml,com/home/conf/struts-category.xml</param-value>
	</init-param>
</filter>
因为设置了<param-name>config</param-name>参数,所以struts-default.xml,struts-plugin.xml等原来

struts2默认加载的文件也需要手动指定,否则不会自动加载。

上面com/home/conf/struts-category.xml采用相对路径即我们需要改变路径的文件,

本例放在了/WEB-INF/classes/com/home/conf/目录下

若不在这里配置struts-default.xml,struts-plugin.xml,也可在struts.xml文件中include将两个文件包含进来。

<include file="struts-default.xml" />
<include file="struts-plugin.xml" />


如若约定大于配置,多个子配置文件的话可以采用扫描的方式如:

<include file="com/home/conf/struts-*.xml" />
或直接
<include file="com/home/conf/*.xml" />


转载请注明出处:http://blog.csdn.net/itmyhome1990/article/details/39344263



Struts2更改配置文件struts.xml默认路径

标签:struts2   配置文件   struts.xml   

原文地址:http://blog.csdn.net/itmyhome1990/article/details/39344263

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!