SSH2框架中配置struts2拦截器报错
严重:Exceptionstartingfilterstruts2.2.1
Unabletoloadconfiguration.-interceptor-ref-file:/D:/software/apache-tomcat-6.0.20-t/apache-tomcat-6.0.20/webapps/recommend/WEB-INF/classes/struts.xml:36:48
atorg.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:428)
...
Causedby:Unabletoloadconfiguration.-interceptor-ref-file:/D:/software/apache-tomcat-6.0.20-t/apache-tomcat-6.0.20/webapps/recommend/WEB-INF/classes/struts.xml:36:48
...20more
Causedby:Unabletofindinterceptorclassreferencedbyref-namemyInterceptor-interceptor-ref-file:/D:/software/apache-tomcat-6.0.20-t/apache-tomcat-6.0.20/webapps/recommend/WEB-INF/classes/struts.xml:36:48
atcom.opensymphony.xwork2.config.providers.XmlConfigurationProvider.buildInterceptorList(XmlConfigurationProvider.java:550)
...22more
2011-3-1811:24:13org.apache.catalina.core.StandardContextstart
严重:ErrorfilterStart
2011-3-1811:24:13org.apache.catalina.core.StandardContextstart
严重:Context[/recommend]startupfailedduetopreviouserrors
2011-3-1811:24:13org.apache.catalina.core.ApplicationContextlog
信息:ClosingSpringrootWebApplicationContext
解决方案:
引起该错误的原因是拦截器的声明和引用没有配置在同一个package下
所以使用拦截器时一定要注意,拦截器的声明和引用必须配置在同一package下
如果如下配置,则一定会报出上述错误,因为拦截器声明在name为portal的package中,而拦截器的引用是在name为test的package中:
<struts>
<constantname="struts.objectFactory"value="spring"/>
<includefile="struts-default.xml"></include>
<packagename="portal"extends="struts-default">
<interceptors>
<interceptorname="myInterceptor"class="authenticationInterceptor">
</interceptor>
</interceptors>
<global-results>
<resultname="login"type="chain">login</result>
</global-results>
<actionname="prepareUserIndex"class="recommendAction"method="prepareUserIndex">
<interceptor-refname="myInterceptor"></interceptor-ref>
<resultname="success">/WEB-INF/jsp/userIndex.jsp</result>
</action>
<actionname="ajaxShowVisitedApps"class="recommendAction"method="showVisitedAppsInfo">
<interceptor-refname="myInterceptor"></interceptor-ref>
<resultname="success">/WEB-INF/jsp/visitedAppsInfo.jsp</result>
</action>
</package>
<packagename="test"extends="json-default">
<actionname="ajaxGetAppRemarkStatus"class="recommendAction"method="getAppRemarkStatus">
<interceptor-refname="myInterceptor1"></interceptor-ref>
<resultname="success"type="json">
<paramname="root">isLiked</param>
</result>
</action>
</package>
</struts>