aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Dependency Injection wiht beanName property 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 wiht beanName property" Watch "Dependency Injection wiht beanName property" New topic
Author

Dependency Injection wiht beanName property

Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

hi,

I have a business interface implemented by two beans and I need to do DI with a certain bean. My session bean code looks like :


and the DI looks like :



if I run this I get

com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref org.mihai.client.Client/counter@jndi: @null@org.mihai.business.Counter@Session@thePourBean into class org.mihai.client.Client


In the specs I have for @EJB - beanName

The ejb-name of the Enterprise Java Bean to which this reference is mapped. Only applicable if the target EJB is defined within the same application or stand-alone module as the declaring component.


According with my code my bean name is "xxxx".
But why I get the exeption ?

Regards,
M
[ August 29, 2008: Message edited by: Mihai Radulescu ]

SCJP, SCJD, SCWCD, OCPJBCD
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

Hi Mihai,

There's nothing wrong in the code snippets you posted. However, you are not telling us where you are injecting your bean: is it into another bean? into a servlet? Also, which container (and version) are you using?

I have tested it myself and it certainly works when you inject the bean into another bean. I have tested it under Glassfish.


SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

Hi Sergio


I inject my bean in a stand alone application and I run this application with the ACC.


I don't understand why on you are working, can you post your test classes.

Regards,
M
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

Hi Mihai,

Sorry, I don't have here the classes I have used (I may have them tomorrow). However, this is what I have done: I created a client and two stateless EJBs. The client calls the first EJB which in turn calls the second. The second EJB is injected in the first EJB. I haven't used injection in the client (just a jndi lookup of the first session bean).

Anyways, the answer is in the quote you posted before: "Only applicable if the target EJB is defined within the same application or stand-alone module as the declaring component". In your case, the client and the EJBs are not defined inside the same ejb-jar or EAR, are they?

I hope you found my explanation usuful. Regards.
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

Hi, Sergio

and thanks, I think that the answer lies in the ejb-module.
I am not so shore what this means - I am just on beginning, I only read the first 100-150 pages from EJB in action.
I don't know if this will answer your question but the bean class is both deploy archive ejb-jar and ear.


Regards,
M
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dependency Injection wiht beanName property