users@glassfish.java.net

Problem accesing stateless session bean from servlet

From: <glassfish_at_javadesktop.org>
Date: Tue, 23 Jun 2009 16:55:26 PDT

Hi. In my servlet, I have tried using @EJB annotation as well as jndi lookup but both did not work. I don't have jndi.properties file and no ejb mapping set in any xml files. Are these necessary? I'm working with GlassFish server v2.1. Below are my classes and the error messages that I got.


public class CreateCustomerServlet extends HttpServlet {

@EJB
ICustomerBean customerBean;

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

      //customerBean = (ICustomerBean) new InitialContext().lookup("CustomerBeanEJB");
        
       List<Customer> list = new ArrayList<Customer>();
      list = customerBean.listCustomer();
}

@Stateless(mappedName="CustomerBeanEJB")
@Remote(ICustomerBean.class)
public class CustomerBean implements ICustomerBean {



    public List listCustomer()
    {

    ArrayList<Customer> list = new ArrayList<Customer>();

    return list;
    }
}

public interface ICustomerBean {

public List listCustomer();

}

The error messages
com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref servlet.CreateCustomerServlet/customerBean_at_jndi: entity.ICustomerBean_at_null@entity.ICustomerBean_at_Session@null into class servlet.CreateCustomerServlet

Not binding factory to JNDI, no JNDI name configured
JNDI InitialContext properties:{}
javax.naming.NameNotFoundException: CustomerBeanEJB not found
[Message sent by forum member 'bubbl3s' (bubbl3s)]

http://forums.java.net/jive/thread.jspa?messageID=352585