我想扩展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