Java-SE アプリケーションでインターセプターを使用したいのですが、Weld を CDI 実装として使用しており、ここでこれをテストしています。
メインクラス:
public static void main(String[] args) {
WeldContainer weldContainer = new Weld().initialize();
Service service = weldContainer.instance().select(Service.class).get();
service.methodCall();
service.methodCallNumberTwo();
}
サービス クラス:
public class Service {
@TestAnnotation
public void methodCall(){
System.out.println("methodCall...!");
methodCallNumberTwo();
}
@TestAnnotation
public void methodCallNumberTwo(){
System.out.println("methodCallNumberTwo...!");
}
}
インターセプタークラス:
@Interceptor
@TestAnnotation
public class TestInterceptor {
@AroundInvoke
public Object interceptorMethod(InvocationContext invocationContext) throws Exception {
System.out.println("I'm the TestInterceptor of "+invocationContext.getMethod());
return invocationContext.proceed();
}
}
そして出力:
I'm the TestInterceptor of public void Service.methodCall()
methodCall...!
methodCallNumberTwo...!
I'm the TestInterceptor of public void Service.methodCallNumberTwo()
methodCallNumberTwo...!
私の質問
最初: methodCallNumberTwo() を呼び出しているときに、インターセプターが methodCall() で呼び出されないのはなぜですか?
2番目: それを変更する方法はありますか?
私はインターセプターの振る舞いを研究しているだけで、理解したいと思っています。前もって感謝します!