2 Replies Latest reply on Mar 13, 2012 2:27 PM by Alessio Soldano

    EJB not injecting in @Webservice

    Tom Verschueren Newbie

      Hi all,

       

      I'm having trouble getting a reference to my UserManager object in my webservice. I have tried injecting with @EJB and by manually looking for it with jndi lookup.  Both with no result. I am using JBoss AS 7.1

       

      I see in the server.log that my UserManager is indeed loaded, and registered with the lookup service

       

      18:33:03,025 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-4) JNDI bindings for session bean named UserManager in deployment unit deployment "SGBackend-2.0-SNAPSHOT.war" are as follows:

                  java:global/SGBackend-2.0-SNAPSHOT/UserManager!be.ugent.ibcn.sg.usermanagement.domain.UserManager

                java:app/SGBackend-2.0-SNAPSHOT/UserManager!be.ugent.ibcn.sg.usermanagement.domain.UserManager

                java:module/UserManager!be.ugent.ibcn.sg.usermanagement.domain.UserManager

                java:global/SGBackend-2.0-SNAPSHOT/UserManager

                java:app/SGBackend-2.0-SNAPSHOT/UserManager

                java:module/UserManager

       

       

      After my jndi lookup, I get following error:

       

      8:33:03,533 ERROR  (MSC service thread 1-3) javax.naming.NameNotFoundException: Error looking up SGBackend-2.0-SNAPSHOT/UserManager, service service jboss.naming.context.java.global."SGBackend-2.0-SNAPSHOT".UserManager is not started

      18:33:03,534 ERROR  (MSC service thread 1-3)           at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:126)

      18:33:03,534 ERROR  (MSC service thread 1-3)           at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:74)

      18:33:03,534 ERROR  (MSC service thread 1-3)           at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:177)

      18:33:03,535 ERROR  (MSC service thread 1-3)           at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:123)

      18:33:03,535 ERROR  (MSC service thread 1-3)           at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:213)

      18:33:03,535 ERROR  (MSC service thread 1-3)           at javax.naming.InitialContext.lookup(InitialContext.java:392)

      18:33:03,536 ERROR  (MSC service thread 1-3)           at be.ugent.ibcn.sg.usermanagement.web.jaxws.UserManagerService.<init>(UserManagerService.java:38)

      18:33:03,536 ERROR  (MSC service thread 1-3)           at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

      18:33:03,537 ERROR  (MSC service thread 1-3)           at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

      18:33:03,537 ERROR  (MSC service thread 1-3)           at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

      18:33:03,537 ERROR  (MSC service thread 1-3)           at java.lang.reflect.Constructor.newInstance(Constructor.java:513)

      18:33:03,538 ERROR  (MSC service thread 1-3)           at java.lang.Class.newInstance0(Class.java:355)

      18:33:03,538 ERROR  (MSC service thread 1-3)           at java.lang.Class.newInstance(Class.java:308)

      18:33:03,538 ERROR  (MSC service thread 1-3)           at org.jboss.wsf.stack.cxf.configuration.NonSpringBusHolder.newInstance(NonSpringBusHolder.java:170)

      18:33:03,539 ERROR  (MSC service thread 1-3)           at org.jboss.wsf.stack.cxf.configuration.NonSpringBusHolder.configure(NonSpringBusHolder.java:96)

      18:33:03,539 ERROR  (MSC service thread 1-3)           at org.jboss.wsf.stack.cxf.deployment.aspect.BusDeploymentAspect.startDeploymentBus(BusDeploymentAspect.java:113)

      18:33:03,540 ERROR (MSC service thread 1-3)           at org.jboss.wsf.stack.cxf.deployment.aspect.BusDeploymentAspect.start(BusDeploymentAspect.java:66)

      18:33:03,541 ERROR  (MSC service thread 1-3)           at org.jboss.as.webservices.deployers.AspectDeploymentProcessor.deploy(AspectDeploymentProcessor.java:81)

      18:33:03,542 ERROR  (MSC service thread 1-3)           at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113)

      18:33:03,542 ERROR  (MSC service thread 1-3)           at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)

      18:33:03,543 ERROR  (MSC service thread 1-3)           at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)

      18:33:03,543 ERROR  (MSC service thread 1-3)           at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

      18:33:03,543 ERROR (MSC service thread 1-3)           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

      18:33:03,544 ERROR (MSC service thread 1-3)           at java.lang.Thread.run(Thread.java:662)

       

       

      The two classes of intrest are:

       

       

      @Startup

      @Singleton

      public class UserManager {

      ...

      }

       

       

       

      @WebService(name = "UserManagerTest",

                          wsdlLocation = "WEB-INF/jaxws/UserManagerService.wsdl")

      public class UserManagerService {

       

                @EJB

                private UserManager userManager;

       

                public UserManagerService() {

                          System.out.println("DEBUG: userManager (EJB): " + userManager);

       

                          try {

                                    InitialContext ctx = new InitialContext();

                                    userManager = (UserManager) ctx

                                                        .lookup("java:global/LinearBackend-2.0-SNAPSHOT/UserManager");

                          } catch (NamingException e) {

                                    e.printStackTrace();

                          }

                            System.out.println("DEBUG: userManager (lookup): " + userManager);

                  }

      ...

      }

       

      Any help would be appreciated,

       

      Tom