如果 ArroundInvoke 方法是从另一个 ejb 方法调用的,它是否会被调用?

发布于 2024-12-18 14:00:10 字数 245 浏览 6 评论 0原文

我有以下情况:

@Interceptors(MyInterceptClass.class)
public void ejbMethod1()
{

}


@Interceptors(MyInterceptClass.class)
public void ejbMethod2()
{
    ejbMethod1();
}

调用 ejbMethod2 是否会导致执行两个拦截器调用?

谢谢。

I've the following case:

@Interceptors(MyInterceptClass.class)
public void ejbMethod1()
{

}


@Interceptors(MyInterceptClass.class)
public void ejbMethod2()
{
    ejbMethod1();
}

Is calling ejbMethod2 causes TWO interceptor calls to be executed?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少女七分熟 2024-12-25 14:00:10

我假设您的意思是 @Interceptors (复数)注释,它定义了将在带注释的方法调用时调用的拦截器类。 @Interceptor 注解(单数)用于注解一个拦截器类。

如果是这样,那么简短的回答是:

拦截器由容器执行。如果您的方法调用不会通过容器,那么它不会被拦截。

因此,以下对 ejbMethod1(): 的调用

@Interceptors(MyInterceptClass.class) 
public void ejbMethod2() {
    ejbMethod1(); 
}

不会激活 MyInterceptClass,因为它是本地调用(非 EJB 调用)。

如果您想再次调用拦截器,则应该使用业务接口,例如:

// Somewhere in the class
@Resource
SessionContext ctx;

@Interceptors(MyInterceptClass.class) 
public void ejbMethod2() {
    // This is explicit call which will go through the EJB Container
    ctx.getBusinessObject(YourEJBClass.class).ejbMethod1();
}

这将进行 EJB 感知调用,并在调用 ejbMethod1() 时命中拦截器。

I'll assume you mean @Interceptors (plural) annotation which defines the interceptor class which will be invoked upon annotated method invocation. @Interceptor annotation (singular) is for annotating a class which is an interceptor.

If so, then short answer is: no.

The interceptor is executed by the container. If your method invocation will not go through the container, then it will not be intercepted.

Therefore the following call to ejbMethod1():

@Interceptors(MyInterceptClass.class) 
public void ejbMethod2() {
    ejbMethod1(); 
}

won't activate the MyInterceptClass as it's the local call (non-EJB one).

If you'd like to call the interceptor once again, you should use business interface, so something like:

// Somewhere in the class
@Resource
SessionContext ctx;

@Interceptors(MyInterceptClass.class) 
public void ejbMethod2() {
    // This is explicit call which will go through the EJB Container
    ctx.getBusinessObject(YourEJBClass.class).ejbMethod1();
}

This will make the EJB-aware call and will hit the interceptor while invoking ejbMethod1().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文