• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dependency Injection DI concept

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
use @EJB(name="nameOfEjb") MyEJBBusinessInterface xyzDI
 
What is that? Is that a mongol hoarde? Can we fend them off with this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic