我想擴展ExceptionMappingInterceptor。我創建了一個監聽器來覆蓋ExceptionMappingInterceptor的publishException(...)方法。但它不會偵聽在應用程序中未處理的全局異常。自定義ExceptionMappingInterceptor不偵聽
這是我的配置。
//處理程序
public class GlobalExceptionHandler extends ExceptionMappingInterceptor
{
private Logger logger = AppLogger.getLogger(this.getClass());
@Override
protected void publishException(ActionInvocation invocation, ExceptionHolder exceptionHolder)
{
logger.error("Global Exception msg: "+ exceptionHolder.getException().getMessage(), exceptionHolder.getException());
super.publishException(invocation, exceptionHolder);
}
}
在struts.xml中
<interceptors>
<interceptor name="sessionInterceptor" class="com.jak.session.SessionInterceptor" />
<interceptor name="exception" class="com.jak.exception.GlobalExceptionHandler" />
<interceptor-stack name="mymatrixxInterceptorStack">
<interceptor-ref name="exception"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="sessionInterceptor"/>
</interceptor-stack>
</interceptors>
<global-results>
<result name="exception" type="tiles">myAccount</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="exception" />
</global-exception-mappings>
<action name="myAccount">
<interceptor-ref name="mymatrixxInterceptorStack"></interceptor-ref>
<result type="tiles">errorPage</result>
</action>
在上傳我得到了一個異常「文件的行動com.dsdar.business.offer.CampaignUpdateAction沒有結果定義和結果輸入'。但是這個異常不是由這個攔截器處理的。我不知道它不聽的原因。
你能更詳細地描述發生什麼事情與你期望發生的事情嗎? – 2012-04-26 16:10:23
這個最近的問題可能會有所幫助(雖然不知道你在做什麼,這很難說)http://stackoverflow.com/questions/10313279/struts-2-how-to-redirect-exceptions-of-type-異常到特定頁面/ 10314822#10314822 – Quaternion 2012-04-26 22:35:00
對不起,描述。我在我的問題中描述了異常細節。你能理解我的問題嗎? – 2012-04-27 14:00:59