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将两个文件包含进来。


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



作者:itmyhome

 出处: http://blog.csdn.net/itmyhome1990/article/details/39344263



相关文章:

  • 2021-12-12
  • 2022-12-23
  • 2021-12-09
  • 2021-11-08
  • 2021-10-20
  • 2021-11-27
  • 2021-04-25
  • 2021-12-28
猜你喜欢
  • 2021-10-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-01
  • 2021-11-05
相关资源
相似解决方案