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
Author

Help with EJB DI

Ronwaldo Cruz
Ranch Hand

Joined: Oct 17, 2006
Posts: 69
Hi,

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
Greenhorn

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

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

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
Hi,

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
Marshal

Joined: Jul 20, 2005
Posts: 9955
    
163

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