Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dependency Injection wiht beanName property

 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic