I have three classes: Main with a method main , an interceptor class with an intercept method, and a class for trying to intercept a method call.
one.
package com.dugin.rostislav.test; public class Main { public static void main(String[] args) { new TestInterceptor().test(); } } 2
package com.dugin.rostislav.test; import javax.interceptor.AroundInvoke; import javax.interceptor.InvocationContext; public class SimpleInterceptor { @AroundInvoke public Object catchCall(InvocationContext context) throws Exception { System.out.println("call catched!"); return context.proceed(); } } 3
package com.dugin.rostislav.test; import javax.interceptor.Interceptors; public class TestInterceptor { @Interceptors(SimpleInterceptor.class) public void test() { System.out.println("test"); } } Dependency in pom.xml :
<dependency> <groupId>javax.interceptor</groupId> <artifactId>javax.interceptor-api</artifactId> <version>1.2</version> </dependency> I expected that before calling the test() method, the catchCall() method would be called, but the catchCall () method was called immediately. Why is this happening and how to intercept the call?