permaculture playing cards
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Dependency Injection DI concept 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 DI concept" Watch "Dependency Injection DI concept" New topic

Dependency Injection DI concept

Juggy Obhi
Ranch Hand

Joined: Jul 02, 2007
Posts: 51
Hi All,

I searched and read almost every thread on DI and Dependency Injection. I learned a lot with all the information but i still have doubts.

If we have an EJB like:

We can get this EJB injected into any Managed Component like Servlets and other EJB's using DI


This is my understanding of Dependency Injection.

I was reading MZ Notes section "Annotations for Environment Entries" i got confused with the concept mentioned there which says:

By Default, the name of the field is combined with name of the class in which the annotation is used and is used directly as the name in the bean's naming context.

According to this

@EJB MyEJBBusinessInterface abcDI; will search for java:comp/env/


@EJB MyEJBBusinessInterface xyzDI; will search for java:comp/env/

so to me these are two different references in the bean's naming context. I want to understand how MyEJB (the bean to be injected) is available to both?

And when we declare this bean

This bean is supposed to be available/placed in the JNDI(Global) or Bean's Naming Context(java:comp/env) (I would be very thankful if some one can explain where exactly) by the container for sure because then only DI can work.

I want to know is this Automatic? I mean just use @Stateless annotation and its done ?? is it??

Thanks in Advance.

[ October 14, 2008: Message edited by: Juggy Obhi ]
[ October 14, 2008: Message edited by: Juggy Obhi ]

It does not matter how many times you fall,what matters is how many times you stand back.
Chaminda Amarasinghe
Ranch Hand

Joined: May 17, 2006
Posts: 404
use @EJB(name="nameOfEjb") MyEJBBusinessInterface xyzDI
I agree. Here's the link:
subject: Dependency Injection DI concept
It's not a secret anymore!