关于struts.xml的自定义位置,在web.xml中的宣言方法

关于struts.xml的自定义位置,在web.xml中的声明方法

最近在配struts.xml的时候碰见的问题,正常情况下,struts.xml是放在src目录下,我想把它放在src-→config目录下,于是乎在web.xml的struts配置处添加了:

<init-param>   

    <param-name>config</param-name>   

    <param-value>struts-default.xml,struts-plugin.xml,classpath:config/struts.xml</param-value>   

</init-param>  

    运行了几次一直报找不到action的错误,后来查资料发现classpath是经过spring编译的即/WEB-INF/classes路径,但是applicationContext.xml文件跟struts.xml在同一目录下:

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:config/applicationContext-*.xml</param-value>

</context-param>

这样写是可以找到的。又查了查发现context的作用范围是application,init-param的作用范围在servlet。

于是乎改写为:

 <init-param>   

   <param-name>config</param-name>   

   <!-- 这里必须采用相对\WEB-INF\classes的相对路径 -->

   <param-value>struts-default.xml,struts-plugin.xml,config/struts.xml</param-value>   

</init-param>  

Bingo,这样就顺利的找到了struts.xml文件,运行成功。