wood burning stoves 2.0*
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 9955

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: http://aspose.com/file-tools
subject: Help with EJB DI
Similar Threads
Problems with EJB Local and using servlets - null pointers
@EJB annotation from servlet and JBoss
Problem with Stateless EJB in JBOSS 4.0.4
HTTPUNIT error....
Another WAS7 issue regarding local session beans