• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

@EJB doing nothing - jboss-4.2.2.GA

 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Varun Chopra
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
 
Varun Chopra
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My mistake, it is working now with above change in web.xml, Thanks
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic