java - Can CDI inject standard library POJOs into an EJB? -


i can inject own pojo managed object this:

import javax.ejb.stateless; import javax.inject.inject; @stateless public class someejb {     @inject     private somepojo somepojo; } 

and have pojo:

// no annotations public class somepojo {    } 

this works fine. if inject ejb jsf backing-bean, can see value of somepojo non-null value, expected.

however, if try inject java.util.date someejb, following exception on deployment:

severe: exception while loading app : weld-001408 unsatisfied dependencies type [date] qualifiers [@default] @ injection point [[field] @inject private someejb.date] org.jboss.weld.exceptions.deploymentexception: weld-001408 unsatisfied dependencies type [date] qualifiers [@default] @ injection point [[field] @inject private someejb.date]     @ org.jboss.weld.bootstrap.validator.validateinjectionpoint(validator.java:311) 

someejb now:

// no annotations public class someejb {     @inject     private date date;     } 

date has public, no-argument constructor, , thought that's cdi need "satisfy dependency". i'm sure behaviour "to spec", there's big hole in understanding of cdi.

can explain why doesn't work? what's difference between somepojo , java.util.date cdi perspective?

context:

  • java ee 6
  • glassfish 3.1.2.2
  • i don't have use-case this. know can specify new date().

i can reproduce eap 6.3 well.

the problem occurs because of using java ee 6. java.util.date located in rt.jar , jar not contain beans.xml file enable cdi. can inject objects jars containing beans.xml.

a common workaround use producer method inject such object. have wirte producer able inject objects arbitrary classes regardless jar belong.

as far know behaviour changed in java ee 7, beans.xml optional in cases: https://blogs.oracle.com/theaquarium/entry/default_cdi_enablement_in_java

hope helps.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -