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 3.0 - Injecting EJB References - confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB 3.0 - Injecting EJB References - confusion" Watch "EJB 3.0 - Injecting EJB References - confusion" New topic

EJB 3.0 - Injecting EJB References - confusion

Saeed Amer
Ranch Hand

Joined: Jan 20, 2004
Posts: 140
Hi there,

Section "16.5 EJB References" (ejb core spec - Page# 414):
Sub-section: " Injection of EJB References" says:

The Bean Provider uses the EJB annotation to annotate a field or setter property method of the bean class as a target for the injection of an EJB reference. The reference may be to a session bean�s business interface or to the local home interface or remote home interface of a session bean or entity bean. The following example illustrates how an enterprise bean uses the EJB annotation to reference another enterprise bean. The enterprise bean reference will have the name java:comp/env/com.acme.example.ExampleBean/myCart in the referencing bean�s
naming context, where ExampleBean is the name of the class of the referencing bean and com.acme.example its package. The target of the reference must be resolved by the Deployer.

I am confused - is this ALL one has to do to inject an EJB reference? Don't we have to specify the following:

  • name
  • beanInterface
  • beanname

  • TIA for help!
    Mark Spritzler

    Joined: Feb 05, 2001
    Posts: 17271

    Nope, the container can figure out based you your interface, what to inject.

    Now, if there is ever a conflict where there could be two or more possibilities, then you can include the JNDI name to help the container out. There are attributes that you can include with @EJB, as in all EJB Annotations, it is just that EJB3 has these smart defaults.


    Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
    How to Ask Questions the Smart Way FAQ
    I agree. Here's the link:
    subject: EJB 3.0 - Injecting EJB References - confusion
    It's not a secret anymore!