This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inject a local bean @EJB

 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I have this problem for the past 3 days, searched the internet during the past days looking for an answer with no use. If internet was a desert i would have been dead by now!
I am sorry if this question seems silly to most of you but yes I am a beginner :s

Now, here is the problem!:
I am trying to inject a local bean into another bean and i keep on getting errors. Based on the code that I am pasting here is the error:


Here is my Local interface and bean



Here is the Bean that's trying to inject BBean


I am using GlassFish and NetBeans to develope and test my project.
BTW I couldn't inject a local bean into a servlet either, I had to make it Remote to get injection to work (JNDI fixed the problem I suppose).
Based on my understanding, since BBean is local, I should use beanName property (or attribute) with @EJB, but it is not working.

I couldn't find a book/tutorial (at least an easy going one) or a resource that explain the dirty work that has to be done just to get resource injection to work, I am talking about DD's that must be configured properly. Examples in tutorials are so straight and nice they even look innocent, but when we try to build the simplest example just to try things Boom, exceptions here blasts there!

Appreciate your help, more than you can imagine!
 
Reza Rahman
author
Ranch Hand
Posts: 580
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remove the bean name from @EJB and you should be fine. Have you looked here: https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html?

Cheers,
Reza
 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Reza,

I am sorry for the late response. Thank you for the reply and link.
I tried it and now i am getting a RuntimeException as the error message says:
Cannot resolve reference Unresolved Ejb-Ref beans.AABean/b@jndi: @null@beans.BLocal@Session@null

I checked the link and it says that if I don't provide name for @EJB the default value is
<fully-qualified name of declaring class>/<field-name>
in my case it will be:
beans.AABean/b which is the name that appears in the Exception's message.

is there anything that I should do in DD and other configuration files? Just in case here are the contents of
sun-web.xml:


web.xml:

I am injecting a remote Bean into a class member of a servlet.

Please any other suggestions on how to get my local bean to work?
 
Reza Rahman
author
Ranch Hand
Posts: 580
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remove the DD entries, it should work as long as packaging is not messed up. Take your time with the FAQ, It outlines how DI annotations, defaults and DDs interact.

Cheers,
Reza
 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Reza,

these DD entries are not related to BBean. Your comment implies that there should not be any entries in the DD, which is the case in my application.
Like I mentioned earlier I am using Netbeans and I use wizards, so I have the standard DD and standard packaging.

I am guessing that things are going wrong with Packaging, but I am not configuring anything related to packaging, in other words: I am going the default/standard


 
Reza Rahman
author
Ranch Hand
Posts: 580
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't use NetBeans. You might want to take a look at our code examples to see if things match up. We also cover packaging in our chapters.

Thanks,
Reza
 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again Reza,

I checked the chapters related to packaging and as we discussed earlier, there is no need to configure anything in XML documents (at least that's what I understood :/)

Any tips please?
 
Alphy Tk
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am also encountering the sae problem.I saw a posting in glassfish forum.
https://glassfish.dev.java.net/issues/show_bug.cgi?id=1573

Any idea how I can package the EJB interface classes in netbeans.

Any idea on how to solve this issue

Alphy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic