我正在玩Java EE。这是我的监控拦截器:
public class MonitoringInterceptor {
@AroundInvoke
public Object monitorMethodCall(InvocationContext ctx) throws java.lang.Exception {
Exception exception = null;
long start = System.currentTimeMillis(); // FIXME: use nanotime
try {
return ctx.proceed();
} catch (Exception e){
exception = e;
throw e; // <- PROBLEM
} finally {
long duration = System.currentTimeMillis() - start;
log(ctx, duration, exception );
}
}
[...]
}
然后我在我的所有豆子中使用这个拦截器:
@Stateless
@Interceptors({MonitoringInterceptor.class})
public class BeanA {
[...]
}
@Stateless
@Interceptors({MonitoringInterceptor.class})
public class BeanB {
@EJB
private BeanA beanA;
public void doit(){
try {
beanA.dosomeThing();
} catch(Exception e) {
// handle...
}
}
}
现在问题是,如果我调用方法BeanB#doit()
并且BeanA#dosomeThing()
抛出异常,我的拦截器将捕获异常以记录错误,传递它然后我的事务得到滚动返回 [!]。
如何解决此问题?