This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Resource Injection. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Resource Injection." Watch "Resource Injection." New topic

Resource Injection.

sasinda Rukshan

Joined: Apr 01, 2011
Posts: 4

concider following entity manager factory injection.

We have specified the <ejb-class> so why do we need to have a <injection-target-class> ?

Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Hi Sasinda

The ejb-class represents the bean corresponding class for the a given environment and the injection-* represents the injection applying point.
More precisely, the ejb-class is used to declare entries in the bean context, all the bean instances from this type may use this entries (via JNDI calls) - please notice the "may use it"; there is no must this is just a declaration.
The injection-target-class is used to specify the injection application point - it means inject this instance in this field.

Even if both elements (ejb-class and injection-target-class) have the same meaning they are used in different contexts.

If you dislike to see the "class" in two places you can remove the <ejb-class> element and use <remote> or <local> with the implemented interface.


sasinda Rukshan

Joined: Apr 01, 2011
Posts: 4

It is sorta covered in the JavaRanch Style Guide.
subject: Resource Injection.
Similar Threads
ejb-local-ref and ejb-ref
Persistence EntityManager injection from ejb-jar.xml
Considering Injection i EJB 3.0
@PersistenceContext - overriding injection using configuation file.
ejb reference in deployment descriptor (without annotations )