I am running Wildfly AS 8.1.0.Final.
I have 2 deployed ear applications each containing 1war+1ejb archive. I try to inject an ejb defined in app1 into another ejb of app2 with the @EJB annotation.
I've specified the lookup attribute "java:global/app1-ear-1.0.0-SNAPSHOT/app1-service/App1ServiceImpl!com.acme.service.App1Service" as found in my JNDI view from the console app (or the server.log on deployment).
For some reason the Injection fails in App2:
Caused by: java.lang.IllegalArgumentException: Can not set com.acme.service.App1Service field com.acme.service.impl.App2ServiceImpl.app1Service to com.acme.service.App1Service$$$view6 at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167) [rt.jar:1.8.0_11] at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171) [rt.jar:1.8.0_11] at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81) [rt.jar:1.8.0_11] at java.lang.reflect.Field.set(Field.java:758) [rt.jar:1.8.0_11] at org.jboss.as.ee.component.ManagedReferenceFieldInjectionInterceptorFactory$ManagedReferenceFieldInjectionInterceptor.processInvocation(ManagedReferenceFieldInjectionInterceptorFactory.java:108) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
If I change the type App1Service to Object in order to successfully proceed to the Injection, I can see (in debug) that the returned proxy got all the methods I need from App1Service interface, however I cannot cast it to the App1Service !!! I also try to create a jboss-deployment-structure.xml in app2 to reference app1 deployment (deployment.app1-ear-1.0.0-SNAPSHOT.ear.app1-service.jar) thinking that it might have been a class loading issue but same problem in the end.....
Is there any good example to simply inject an EJB with a Local View into another app running in the same wildfly instance.? I don't understand what I'm doing wrong.....