I have a problem with CDI interceptors. In my EJB module, I am creating an interceptor annotation and my implementation, I also added an implementation class to beans.xml. I have an abstract class called AbstractFacade, and some classes are made from it. In one class, I override the create method and add my interceptor annotation to it. Now in the web module I have an ejb bean instance with an interceptor annotation, but the link to it is of type AbstractFacade. When I call the create method on this link, the corresponding method in the ejb module is called (this one with the annotation), but my interceptor is not called, but if I pass this link to its real type and the create interceptor call will work correctly. I'm not sure if I managed to describe it well, so here are the codes:
FooInter.java
package foo; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import javax.interceptor.InterceptorBinding; @InterceptorBinding @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD}) public @interface FooInter{}
FooInterImpl.java
package foo; import javax.interceptor.AroundInvoke; import javax.interceptor.Interceptor; import javax.interceptor.InvocationContext; @Interceptor @FooInter public class FooInterImpl { @AroundInvoke public Object fuckCall(InvocationContext context) throws Exception { System.out.println("Interceptor: it works"); return context.proceed(); } }
beans.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> <interceptors> <class>foo.FooInterImpl</class> </interceptors> </beans>
AbstractFacade.java
public abstract class AbstractFacade<T> {
Foofacade.java
@Stateless public class FooFacade extends AbstractFacade<Foo> {
OK, and this is at war:
EditHelper.java
public abstract class EditHelper<T> { protected T entity;
FooEditHelper.java
public class FooEditHelper extends EditHelper<Foo> { @EJB private FooFacade fooFacade;
I do not know why getFacade (). create (entity); will not fire an interceptor. I will be very happy for any help.
source share