aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Dependency Injection DI concept" Watch "Dependency Injection DI concept" New topic
Author

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



AND




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/com.foo.abc.MyABC/abcDI

AND

@EJB MyEJBBusinessInterface xyzDI; will search for java:comp/env/com.foo.xyz.MyXYZ/xyzDI

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: 402
use @EJB(name="nameOfEjb") MyEJBBusinessInterface xyzDI
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dependency Injection DI concept
 
Similar Threads
@EJB
newbie error
DI question
EJB 3.0 - Injecting EJB References - confusion
Dependency Injection Failure can't figured out the reason.