提交/回滚后对CMT的监听器支持

时间:2014-01-06 11:35:21

标签: java jpa ejb-3.0 weblogic11g

我有一个要求,我需要知道容器管理事务何时为无状态会话bean提交事务。我希望有一种侦听器系统的拦截器,我可以在TransactionManager上挂钩,但没有任何明显的提供这个。 在容器提交/回滚事务之后有没有办法挂钩自定义代码?

1 个答案:

答案 0 :(得分:0)

使用EJB-3 Interceptor可以解决问题。我想,你想在这个方法的过程之后做点什么。

public class MyInterceptor {
    @AroundInvoke
    public Object intercept(InvocationContext ctx) throws Exception {
        //Here before process of doSomething()
        Object result = ctx.proceed();
        //Here after process of  of doSomething()
        return result;
    }   
}


@Interceptors(MyInterceptor.class)
public <your-ejb-bean> {
    public void doSomething(){
    }
}