自定义ExceptionMappingInterceptor未侦听

时间:2012-04-26 14:07:09

标签: exception exception-handling struts2

我正在尝试扩展ExceptionMappingInterceptor。我创建了一个覆盖ExceptionMappingInterceptor的publishException(...)方法的监听器。但它并没有监听应用程序中未处理的任何全局异常。

以下是我的配置。

//处理程序

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和结果输入”。但是这个拦截器没有处理这个异常。我不知道为什么不听。

1 个答案:

答案 0 :(得分:0)

在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>--><!-- Here!! -->

            <interceptor-ref name="myDefaultStack"></interceptor-ref><!--  Here!!  -->

            <interceptor-ref name="sessionInterceptor" />
        </interceptor-stack>

        <interceptor-stack name="myDefaultStack">

            <!-- <interceptor-ref name="exception"/> --><!-- Here!! -->

            <interceptor-ref name="alias" />
            <interceptor-ref name="servletConfig" />
            <interceptor-ref name="i18n" />
            <interceptor-ref name="prepare" />
            <interceptor-ref name="chain" />
            <interceptor-ref name="debugging" />
            <interceptor-ref name="scopedModelDriven" />
            <interceptor-ref name="modelDriven" />
            <interceptor-ref name="fileUpload" />
            <interceptor-ref name="checkbox" />
            <interceptor-ref name="multiselect" />
            <interceptor-ref name="staticParams" />
            <interceptor-ref name="actionMappingParams" />
            <interceptor-ref name="params">
                <param name="excludeParams">dojo\..*,^struts\..*</param>
            </interceptor-ref>
            <interceptor-ref name="conversionError" />
            <interceptor-ref name="validation">
                <param name="excludeMethods">input,back,cancel,browse</param>
            </interceptor-ref>
            <interceptor-ref name="workflow">
                <param name="excludeMethods">input,back,cancel,browse</param>
            </interceptor-ref>
        </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>

我不懂英语。原因是,请问某人。 (&gt; _&lt;)