aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes @EJB doing nothing - jboss-4.2.2.GA 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 "@EJB doing nothing - jboss-4.2.2.GA" Watch "@EJB doing nothing - jboss-4.2.2.GA" New topic
Author

@EJB doing nothing - jboss-4.2.2.GA

Varun Chopra
Ranch Hand

Joined: Jul 10, 2008
Posts: 211
I have a stateless session bean and a servlet. I have declared a private variable like below in servlet:



But above code is doing nothing. Servlet is in a .war module, ejb is in a .jar module and both are in same ear file.
When mySessionBean is accessed in a method nullpointerexception is thrown. Basically mySessionBean is never set. Can anybody help here?

-Varun -
(My Blog) - Online Certifications - Webner Solutions
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10289
    
168

Injection of EJB in a servlet is not supported in JBoss-4.2.x. You will have to use JBoss-5.0 GA for this.


[My Blog] [JavaRanch Journal]
Varun Chopra
Ranch Hand

Joined: Jul 10, 2008
Posts: 211
Thanks.
Varun Chopra
Ranch Hand

Joined: Jul 10, 2008
Posts: 211
With JBOss 4.2.2 I looked up the EJB programmatically and it worked.
Now I have installed JBoss 5, and I am trying to inject ejb and EntityManager in servlet as below:



But above variables are never set.
Do I have to configure anything in JBoss 5 to enable auto injection? There's not exception either.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10289
    
168

I guess you are not using version 2.5 of the web_app xsd in your web.xml. You will need this for the injection to take place:

Varun Chopra
Ranch Hand

Joined: Jul 10, 2008
Posts: 211
I was not using that. But even after its use, this is not working.
Note that this is a project with several EJBs from ejb 2.1. I upgraded one to EJB 3. EJB 2.1's are packaged in ejb2.1.jar and this single EJB 3 with its local interface is packaged in ejb3.jar. ejb2.1 beans are working fine. Even ejb3 bean works fine if I explicitly look it up. Only DI is not working in servlet when I try to inject ejb3.

I have not defined <ejb-ref > tag for EJB 3 session bean in web.xml. Is that necessary? I guess it should not be because explicit lookup finds it and I am able to use it. Any more hints?




Varun Chopra
Ranch Hand

Joined: Jul 10, 2008
Posts: 211
My mistake, it is working now with above change in web.xml, Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: @EJB doing nothing - jboss-4.2.2.GA