7 Replies Latest reply on Oct 2, 2014 7:02 AM by Francesco Apollonio

    @Inject doesn't work, @EJB works

    Francesco Apollonio Newbie

      Hi all,


      I've a problem on mine application related to the @Inject method.

      I've a local interface (called LocalInterface) that is mostly implemented by an Abstract class (called MyAbstractBean).


      interface LocalInterface<? extends Something> {

           MyObject method1();



      abstract class MyAbstractBean implements LocalInterface {


           abstract MyObject method1()



                // ... do some stuff





           abstract MyObject2 method2();




      This interface uses generics and it's extended by another one (ActualLocalInterface) which has an implementation (ActualLocalInterfaceBean) which extends MyAbstractBean, implementing the remaining abstract methods.



      interface ActualLocalInterface extends LocalInterface<Something>

      { }



      class ActualLocalInterfaceBean implements ActualLocalInterface extends MyAbstractBean



           MyObject2 method2()


                // ... do something





      In another interface (RemoteInterface) implementation (RemoteInterfaceBean) I inject with @Inject the ActualLocalInterface and, in one of the methods, I calls one of the method implemented into MyAbstractBean.


      interface RemoteInterface


          void remoteMethod1();



      class RemoteInterfaceBean




           ActualLocalInterface myLocalBean;

           void remoteMethod1()







      Sometimes the method invocation fails giving me this exception:


      Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class

              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

              at java.lang.reflect.Method.invoke(Method.java:606)

              at org.jboss.weld.util.reflection.Reflections.invokeAndUnwrap(Reflections.java:401)

      when the remote interface's method invoke the MyAbstractBean method. I noticed that stopping and restarting Jboss the behaviour changes and it may start to work. I add also that the application works well on Jboss6 and Jboss7.

      I've found that changing the injection method (from @Inject -> @EJB) the application starts to work well.

      Do you know why? Is it a bug on wildfly?

      Thank you,