Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@EJB doing nothing - jboss-4.2.2.GA

 
Varun Chopra
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • 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?
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks.
 
Varun Chopra
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • 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
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
My mistake, it is working now with above change in web.xml, Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic