This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Inject a local bean @EJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Inject a local bean @EJB" Watch "Inject a local bean @EJB" New topic
Author

Inject a local bean @EJB

Musab Al-Rawi
Ranch Hand

Joined: Aug 06, 2007
Posts: 231
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!


SCBCD - SCWCD - SCJD - SCJP - OCA
Reza Rahman
author
Ranch Hand

Joined: Feb 01, 2005
Posts: 580
    
    5
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


Independent Consultant — Author, EJB 3 in Action — Expert Group Member, Java EE 6 and EJB 3.1
Musab Al-Rawi
Ranch Hand

Joined: Aug 06, 2007
Posts: 231
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

Joined: Feb 01, 2005
Posts: 580
    
    5
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

Joined: Aug 06, 2007
Posts: 231
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

Joined: Feb 01, 2005
Posts: 580
    
    5
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

Joined: Aug 06, 2007
Posts: 231
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

Joined: Jul 23, 2009
Posts: 1
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
 
GeeCON Prague 2014
 
subject: Inject a local bean @EJB