I'm currently facing some issues with EJB 3.1 and CDI 1.2 on Wildfly 8.2.0.Final. I think that CDI and EJB are not fully interoperable as this is suggested everywhere in the web.
My setup is the following:
EAR A
|
+- JAR A.1 (containing some Stateless Session Beans)
+- JAR A.2 (containing some persistence things)
EAR B
|
+- JAR B.1 (containing some classes that use A.1)
Further info:
- The session beans of A.1 use @EJB to inject other session beans of the same module
- CDI is activated for A.1
- EAR B has a jboss-deployment-structure.xml that declares a dependency from B.1 to A.1, aso.
- CDI is activated for B.1
- In order to avoid the need for explicit lookups (@EJB(lookup="java:global/...)) for dependency injection in module B.1, the injection of the session beans (DAOs) of module A.1 shall be done using CDI's @Inject.
Now here are two core problems:
- If module A.1 would include a persistence.xml and with activated CDI, CDI would complain about a missing persistence unit as soon as I try to deploy module B with the dependency B.1 -> A.1
- This is the reason I outsourced the persistence declarations to A.2 which is an ugly workaround but I could live with that.
- see this bug: https://issues.jboss.org/browse/WELD-1851
- I think EJB and CDI are not fully compatible since if I inject a stateless session bean in a class in another module (different deployment with a different classloader) the @EJB injects of the session bean are simply ignored.
- It seems that the session bean's class is instantiated using CDI and not EJB in that case.
- This seems to be a major incompatibility of CDI and EJB as I don't want to care about how the DAOs of A.1 are implemented. I just want to inject an instance of an interface in my application and use it.
Does anyone know how to work around those issues or what causes this behavior?
Thanks a lot!