I can inject my own POJO into a managed object like this:
import javax.ejb.Stateless;
import javax.inject.Inject;
@Stateless
public class SomeEjb {
@Inject
private SomePojo somePojo;
}
And I have this POJO:
// No annotations
public class SomePojo {
}
This works fine. If I inject the EJB into a JSF backing-bean, I can see that the value of somePojo
is non-null value, as expected.
However, if I try to inject a java.util.Date
into SomeEjb
, I get the following exception on deployment:
Severe: Exception while loading the app : WELD-001408 Unsatisfied dependencies for type [Date] with qualifiers [@Default] at injection point [[field] @Inject private SomeEjb.date]
org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [Date] with qualifiers [@Default] at injection point [[field] @Inject private SomeEjb.date]
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:311)
SomeEjb now:
// No annotations
public class SomeEjb {
@Inject
private Date date;
}
Date has a public, no-argument constructor, and I thought that's all CDI would need to "satisfy the dependency". I'm sure this behaviour is "to spec", but clearly there's a big hole in my understanding of CDI.
Can someone explain why this doesn't work? What's the difference between SomePojo
and java.util.Date
from a CDI perspective?
Context:
- Java EE 6
- GlassFish 3.1.2.2
- I don't have a use-case for this. I know that I can just specify
new Date()
.