Can CDI inject standard POJO libraries into EJBs?

I can enter my own POJO in a managed entity, for example:

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 {   
}

It works great. If I embed EJB in JSF bean support, I see that the value somePojois a nonzero value, as expected.

However, if I try to type java.util.Datein 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)

Someeyb:

// No annotations
public class SomeEjb {
    @Inject
    private Date date;    
}

The date has an open constructor with no arguments, and I thought that all CDIs would have to “satisfy dependency”. I'm sure this behavior is "specified", but obviously there is a big hole in my understanding of CDI.

Can someone explain why this is not working? What is the difference between somePojoand java.util.Datein terms of CDI?

Context:

  • Java EE 6
  • GlassFish 3.1.2.2
  • . , new Date().
+4
1

EAP 6.3.

, , - Java EE 6. java.util.Date rt.jar, JAR beans.xml, CDI. JAR, beans.xml.

. , , , JAR .

, , Java EE 7, beans.xml : https://blogs.oracle.com/theaquarium/entry/default_cdi_enablement_in_java

, .

+3

Source: https://habr.com/ru/post/1584102/


All Articles