0
votes

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:

  1. 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
  2. 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!

1
What makes you think anything at all in EAR A will be accessible from EAR B? Even if you manage to wangle the class loading issues via jboss-deployment-structure.xml you're stepping outside the bounds of the specs and I would not expect much annotation processing to work. Why not just put copies of jars A.1 and A.2 into EAR B? - Steve C

1 Answers

0
votes

Theoretically you can let EAR A depend on EAR B (using jboss-deployment-structure.xml by adding a module dependency to deployment.ear.b or something). If EAR B's META-INF contains the CDI activation file (beans.xml) EAR A could probably inject dependencies from EAR B.

In JBoss AS7 and WildFly 8 deployments can, in most cases, be treated like 'normal' modules.