File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes EJB ref Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB ref" Watch "EJB ref" New topic

EJB ref

aakash bhatt
Ranch Hand

Joined: Jan 09, 2003
Posts: 182
What is EJB ref, while deploying an EJB
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
The ejb-ref elements in the standard ejb-jar.xml are used to specify logical references to another EJB the one being described is going to use. It's basically a promise/requirement saying "the application deployer must map this reference to a real JNDI name upon deployment".
For example, you have an EJB called CustomerBean that needs to use the AccountBean. You could just lookup the AccountBean from CustomerBean using the JNDI name that was used to deploy AccountBean with. This approach does have its sore points however. What happens if the application deployer finds out that the JNDI name the bean developer had assumed cannot be used in the production environment for some reason? The solution would be to abstract the real JNDI name from the CustomerBean by using ejb-ref.
The ejb-jar.xml of CustomerBean would define an ejb-ref so that CustomerBean code can use "java:comp/env/XXX" to lookup the AccountBean where "XXX" is anything the deployer wills. It is then the application deployer's job to specify the link between ejb-ref and the real JNDI name. With WebLogic, for example, this is done using weblogic-ejb-jar.xml (i.e. using the vendor-specific deployment descriptor).

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
I agree. Here's the link:
subject: EJB ref
It's not a secret anymore!