GeeCON Prague 2014*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Dependency injection using Deployment descriptors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Dependency injection using Deployment descriptors" Watch "Dependency injection using Deployment descriptors" New topic
Author

Dependency injection using Deployment descriptors

Senthil Kumar
Ranch Hand

Joined: Mar 13, 2006
Posts: 264
How dependency injection is done using DD file.I have seen the tag <injection-target> in an article. But haven't find that in specs. is this the only tag available. where can i find the information about injection tags


when you really want something, all the universe always conspires in your favour.<br /> <br />SCJP1.5-77%<br />SCWCD-89%
Andor Nemeth
Greenhorn

Joined: Jul 06, 2007
Posts: 16
In this book! Chapter, section: 14.2!
http://www.oreilly.com/catalog/entjbeans5/


SCJP 5<br />SCBCD 5 (next target)
Andor Nemeth
Greenhorn

Joined: Jul 06, 2007
Posts: 16
Originally posted by Senthil Kumar SS:
How dependency injection is done using DD file.I have seen the tag <injection-target> in an article. But haven't find that in specs. is this the only tag available. where can i find the information about injection tags


The <injection-target> element is used if you want to inject an EntityManagerFactory into an EJB's bean class.

<persistence-unit-ref> <persistence-unit-ref-name>persistence/YourDB</persistence-unit-ref-name>
<persistence-unit-name>YourDB</persistence-unit-name>
<injection-target> <injection-target-class>org.andir.YourBean</
injection-target-class>
<injection-target-name>yourField</injection-target-name>
</injection-target>
</persistence-unit-ref>

The EntityManager is injected into the field named yourField or passed as a parameter to a setter method named setYourField( ) in YourBean class.

(I've modified the example a bit, because i didn't wanted to quote totally the book!)
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

It's also in EJB3 in Action, in Appendix D. But there's no example. It's not only for EntityManagerFactory. It's used to inject anything like a resource, an EJB, an entity manager...


[My Blog]
All roads lead to JavaRanch
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

You'll find an example in the core spec, to inject environment entries :
16.4.1.3 Declaration of Simple Environment Entries in the Deployment Descriptor
 
GeeCON Prague 2014
 
subject: Dependency injection using Deployment descriptors