I've been struggling for this for a while now.
I'm trying to gear up for EJB 3.0. I'm using JBoss 5.1.0 GA as my application server. I started with very simple stateless session bean with local interface and a simple jsp-servlet client which invokes session bean method. All this while I've been trying to use @EJB
annotation to inject session bean into the servlet class.
public class SampleServlet extends HttpServlet {
@EJB
private PersonLocal person;
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("In servlet");
response.getWriter().write("Person Name : "+person.getName());
System.out.println(person.getName());
}
}
I'm using JBoss 5.1.0 GA with the default configuration. (I also tried with all configuration)
However, I used to get a null reference to the session bean injection. After struggling for a day or so, I finally tried the ugly EJB 2.x JNDI lookup method instead of @EJB
annotation with configuration for jndi specified in the jndi.properties
file and it worked without any other changes!
Now, I tried to find out in the JBoss docs whether JBoss 5.1.0 GA does or does not support the injection with @EJB
annotation, but couldn't find a concrete answer. So can someone tell me whether it does? cause I would really prefer annotation over JNDI lookup (I mean, who will not?). Am i missing something..?
Probably should have put this in the JBoss forums, but.. I'm addicted to this place ;-)