次のケースがあります。
@Interceptors(MyInterceptClass.class)
public void ejbMethod1()
{
}
@Interceptors(MyInterceptClass.class)
public void ejbMethod2()
{
ejbMethod1();
}
ejbMethod2 を呼び出すと、2 つのインターセプター呼び出しが実行されますか?
ありがとう。
次のケースがあります。
@Interceptors(MyInterceptClass.class)
public void ejbMethod1()
{
}
@Interceptors(MyInterceptClass.class)
public void ejbMethod2()
{
ejbMethod1();
}
ejbMethod2 を呼び出すと、2 つのインターセプター呼び出しが実行されますか?
ありがとう。
@Interceptors
アノテーション付きメソッドの呼び出し時に呼び出されるインターセプタークラスを定義する(複数の)アノテーションを意味すると仮定します。@Interceptor
注釈 (単数) は、インターセプターであるクラスに注釈を付けるためのものです。
もしそうなら、短い答えは: noです。
インターセプターはコンテナーによって実行されます。メソッド呼び出しがコンテナーを通過しない場合、傍受されません。
したがって、次の への呼び出し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()
ます。