This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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: @firstname.lastname@example.org.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 ]
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.
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?
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.