I want to use interceptors in a Java-SE application and I am using weld as CDI implementation and i'm testing this here:
The Main-Class:
public static void main(String[] args) {
WeldContainer weldContainer = new Weld().initialize();
Service service = weldContainer.instance().select(Service.class).get();
service.methodCall();
service.methodCallNumberTwo();
}
The Service-Class:
public class Service {
@TestAnnotation
public void methodCall(){
System.out.println("methodCall...!");
methodCallNumberTwo();
}
@TestAnnotation
public void methodCallNumberTwo(){
System.out.println("methodCallNumberTwo...!");
}
}
The Interceptor-Class:
@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 the output:
I'm the TestInterceptor of public void Service.methodCall()
methodCall...!
methodCallNumberTwo...!
I'm the TestInterceptor of public void Service.methodCallNumberTwo()
methodCallNumberTwo...!
My Questions
First: Why isn't the interceptor called in methodCall() when i'm calling methodCallNumberTwo()?
Second: Is there a way to change that?
I'm only studying the behavior of interceptors and want to understand. Thank you in advance!