In an .ear file with JAX-RS resources in the lib directory, it is impossible to have CDI inject an EJB implementation into a JAX-RS resource.
I have an .ear file with a lib directory.
In the .ear file I have:
- an "api" .jar in the lib directory consisting of a single interface (a business interface)
- an EJB module (a .jar file at the root level containing a local stateless session bean implementing the business interface described above, and a META-INF/beans.xml file causing it to be a CDI bean archive
- a "jaxrs" .jar in the lib directory containing a single JAX-RS resource class with an injection point in it declared as @Inject private Greeter greeter; (where Greeter is the business interface), and a META-INF/beans.xml file causing it to be a CDI bean archive
- a .war file containing a single class that extends javax.ws.rs.core.Application and serves as the "mount point" for a JAX-RS application whose single resource is the resource described above
Through various permutations of this application, deployment fails with Weld claiming that it cannot satisfy the Greeter injection point.
If I get CDI out of the mix and put @ManagedBean on the resource class and change the @Inject to @EJB everything works fine. But I want to use CDI injection, not @EJB injection.
I have attached a test case. Unzip/Untar it and run mvn clean install on it. Then deploy the resulting .ear file. It will be available under (e.g.) http://localhost:8080/cdi-jaxrs-war/api/greeting.