问题
Ear file:
ear
+--lib
| +--API jar
| | +-- com.foobar.Greeter.class (interface)
| | (look, ma, no META-INF/beans.xml on purpose)
| |
| +--JAX-RS endpoint jar
| +-- com.foobar.GreeterResource.class (has @Inject Greeter greeter;)
| +-- META-INF/beans.xml
|
+--EJB jar
| +-- com.foobar.GreeterBean implements com.foobar.Greeter (@Stateless, @Local)
| +-- META-INF/beans.xml
|
+--JAX-RS skinny war (no libs)
+-- WEB-INF/beans.xml (maybe not necessary?)
+-- WEB-INF/classes/com.foobar.Application
(empty subclass of JAX-RS Application)
To recap in English:
- API jar file. Contains
Greeter
interface. Present inlib
directory. - EJB jar file. Contains a
@Stateless
@Local
EJB that implementsGreeter
. Also contains aMETA-INF/beans.xml
file. CDI says this is necessary to make this a bean archive. - Skinny war. Exists only to have an (empty)
Application
class in it to serve as the bootstrappy part of JAX-RS. Endpoints are NOT located within. Contains aWEB-INF/beans.xml
file, though I confess I'm not sure this is necessary, since by definitionWEB-INF/beans.xml
marks only theclasses
directory (which here does not exist) as a bean archive. - JAX-RS endpoint jar file. This one's slightly weird. Present in the
.ear
lib
directory, so on the classpath, but not in the.war
file'slib
directory (on purpose). Discovered—per the JAX-RS 1.1 specification—automatically by the JAX-RS application, so classes within it are probably in a kind of tug-of-war between JAX-RS and CDI.GreeterResource
contains@Inject Greeter greeter;
.
Deploying this in GlassFish 3.1.2.2 (Weld 1.1.8) yields an unsatisfied dependency error for the @Inject
location. WTF?
Why? The only Greeter
instance in the whole application is an EJB implementation, which is in a bean archive. The resource class is in a bean archive. I read the specification as saying that session beans automatically have their business local interfaces registered as bean types.
来源:https://stackoverflow.com/questions/18008321/cdi-why-are-there-unsatisfied-dependencies-in-the-following-setup