jQuery in Action, 3rd edition
The moose likes EJB and other Java EE Technologies and the fly likes Injecting EJB into servlet 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 "Injecting EJB into servlet" Watch "Injecting EJB into servlet" New topic

Injecting EJB into servlet

Alejandro Dominguez

Joined: Jun 01, 2007
Posts: 28
Hi to all,

my ear file contains the ejb.jar and webapp.war files; in my webapp I have a servlet into which I'd like to inject an EJB reference.

From the servlet, the following code works perfectly:

However, trying to achieve the same by injection, results in a NullPointerException as soon as I try to run one of the bean's methods

Am I missing something here?


Alejandro<br /> <br />SCJP 5 (SAI)
Lave Kulshreshtha
Ranch Hand

Joined: Oct 21, 2007
Posts: 106
Can you please provide some more details?


SCJP 1.4, SCWCD 1.4, SCBCD 1.3, ITIL V3 Foundation Certification
Vesa Tanhua-Tyrkk�

Joined: Jan 16, 2008
Posts: 25

I think that injection is not possible in web tier.
So jndi lookup is the only possible option.
Edvins Reisons
Ranch Hand

Joined: Dec 11, 2006
Posts: 364

you may want to check your server against the list of Java EE 5 compatible servers here
PK Ghosh

Joined: Aug 08, 2006
Posts: 24

I know JBoss 4.0.4 does not support EJB injection into servlet container. It suppose to fix on 5.0
Alejandro Dominguez

Joined: Jun 01, 2007
Posts: 28
I'm Using JBoss 4.2.2 GA, so maybe that's the problem... oh well, I'll stick to jndi lookup meanwhile.

Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10441

Yes, JBoss4.2.2 does not support EJB injection in servlets.

[My Blog] [JavaRanch Journal]
I agree. Here's the link: http://aspose.com/file-tools
subject: Injecting EJB into servlet
It's not a secret anymore!