Я хочу использовать перехватчики в приложении Java-SE, и я использую сварку в реализации CDI и я тестирую здесь:Почему перехватчик не вызван в том же классе обслуживания?
Главного-Class:
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();
}
}
Aaaand выход:
I'm the TestInterceptor of public void Service.methodCall()
methodCall...!
methodCallNumberTwo...!
I'm the TestInterceptor of public void Service.methodCallNumberTwo()
methodCallNumberTwo...!
Мои вопросы
Первый: Почему не перехватчик называется в methodCall(), когда я звоню methodCallNumberTwo()?
Во-вторых: Есть ли способ изменить это?
Я изучаю поведение перехватчиков и хочу понять. Заранее спасибо!
Возможный дубликат [Java CDI. Перехватчик запускается только при первом вызове метода в классе] (http://stackoverflow.com/questions/32129910/java-cdi-interceptor-is-only-invoked-in-the-first-method-call-in- класс) – lucasvc