Rodrigo Villalba Zayas Rodrigo Villalba Zayas - 2 months ago 19
Java Question

Java CDI. Interceptor is only invoked in the first method call in a class

I'm using CDI Interceptors and I've realized that only the first method call in a class annotated with @Interceptor is intercepted. In the example below methodB is never intercepted.

public @interface Transactional {


public class TransactionsInterceptor {

public Object transactionInterceptor(InvocationContext context) throws Exception {

return context.proceed();


public Interface AnImportantInterface {
public void methodA();
public void methodB();

public class AnImportantClass implements AnImportantInterface {

public void methodA() {


public void methodB() {

//This method is never intercepted


public class AnotherImportantClass {
@Inject AnImportantInterface aui;

public void someMethod() {

How can I achieve that methodB be intercepted if methodA is called first? is there some workaround?


It's because you are calling methodB() directly and not via the CDI proxy so the interceptor is never invoked. Interceptors will only be invoked when the CDI bean method is called using its proxy. You should move method B into another CDI bean and @Inject it into this one and from methodA change methodB() to bean2.methodB(..).