This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Help with EJB DI 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 "Help with EJB DI" Watch "Help with EJB DI" New topic

Help with EJB DI

Ronwaldo Cruz
Ranch Hand

Joined: Oct 17, 2006
Posts: 69

Currently I'm getting a nullpointer exception on my servlet that uses an EJB.

Here is my servlet

Here is my EJB

Here's my application.xml

I have deployed both the war file and the ejb jar file into a single EAR file. Is there something more I need to do? Thank you.

Sonal Popat

Joined: May 10, 2010
Posts: 9
In web.xml file add servlet-name, servlet-class and servlet mapping tags.

<servlet-class>com.test.servlet.HelloServlet</servlet-class> /* package name of your HelloServlet */

deploy both the projects independently and in your browser try the http://localhost:8080/YourWARProjectName/HelloServlet

SCJP 6.0 93%
Ronwaldo Cruz
Ranch Hand

Joined: Oct 17, 2006
Posts: 69

I have done this and I get null pointer exception on my servlet because the container did not inject the EJB into the servlet.

For EJB to EJB DI it works ok. I can also find the EJB remotely through JNDI.

Seems DI doesn't work in Glassfish for Web and EJB
Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10441

What does your web.xml look like? See if this helps.

[My Blog] [JavaRanch Journal]
Ronwaldo Cruz
Ranch Hand

Joined: Oct 17, 2006
Posts: 69
Thanks. This really helped
I agree. Here's the link:
subject: Help with EJB DI
It's not a secret anymore!