I'm trying to inject a stateless EJB into servlet.
But it is not working. Did I understand something wrong?
If I do this in a @WebService
annotated class, I can use the injected EJB without problems.
My EJB:
@Stateless
public class doSomethingService
{
public void doSomething()
{
System.out.println("DO SOMETHING");
}
}
My Servlet:
@WebServlet("/testservlet")
public class test_servlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
@Inject
private doSomethingService injBean;
public test_servlet()
{
super();
injBean.doSomething();
}
This causes a NullPointerException
. I tried to do a JNDI-Lookup and it worked very well. Is it a fact that @Inject
does not work in Servlets?
Im using Glassfish 3.1.2.2