users@glassfish.java.net

EJB injection into servlet

From: <glassfish_at_javadesktop.org>
Date: Thu, 06 Nov 2008 08:41:44 PST

I have a stateless session bean defined as follows:

@Stateless(name="keyregistry/LocationManager")
public class LocationManager extends BaseSessionBean implements ILocationManagerRemote, ILocationManager {
...
}

I have a servlet defined as follows:

public class EJBManagerServlet extends HttpServlet {
        private static final long serialVersionUID = 1L;
    
        @EJB(beanName="keyregistry/LocationManager")
        private ILocationManagerRemote locationManager;

        @Override
        public void init() throws ServletException {
                if (locationManager == null) {
                        System.err.println("Location manager is null!!!");
                }
        }
}

The servlet is defined with a load-on-startup setting of 2. When the servlet gets loaded and initialized, the "Location manager is null!!!" string gets printed to the log.

The session bean lives in KeyRegistry-EJB.jar. The servlet lives in KeyRegistry-Web.war. Both archives are in KeyRegistry.ear.

Any help with this would be much appreciated.
[Message sent by forum member 'kdeanddd' (kdeanddd)]

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