• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with EJB DI

 
Ronwaldo Cruz
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


 
Ronwaldo Cruz
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does your web.xml look like? See if this helps.
 
Ronwaldo Cruz
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. This really helped
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic