jersey
  1. jersey
  2. JERSEY-1819

UnsatisfiedDependencyException - @Inject into @Stateless @Path not working

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0-rc1
    • Component/s: None
    • Labels:
      None
    • Environment:

      GF 4.0 b81 - Win7 64bit

      Description

      Given:

      @Stateless
      @Path("person")
      public class NotWorkingStateless {

      @Inject
      Logger l;

      @GET
      public void doWork()

      { l.log(Level.INFO, "Not Working"); }

      }

      called via http://localhost:8080/inject-logger/webresources/person

      leads to a

      SEVERE: EJB5070: Exception creating stateless session bean : [NotWorkingStateless]
      WARNING: EJB5184:A system exception occurred during an invocation on EJB NotWorkingStateless, method: public void net.eisele.inject.logger.NotWorkingStateless.doWork()
      WARNING: javax.ejb.EJBException: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB
      at com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:435)
      at com.sun.ejb.containers.BaseContainer.getContext(BaseContainer.java:2534)
      at com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:1924)
      at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:210)
      at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
      at $Proxy270.doWork(Unknown Source)
      at net.eisele.inject.logger._EJB31_GeneratedNotWorkingStatelessIntf__Bean_.doWork(Unknown Source)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
      at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:125)
      at org.glassfish.jersey.server.model.internal.VoidVoidDispatcherProvider$VoidToVoidDispatcher.doDispatch(VoidVoidDispatcherProvider.java:77)
      at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:91)
      at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:350)
      at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:345)
      at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
      at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:214)
      at org.glassfish.jersey.internal.Errors$1.call(Errors.java:207)
      at org.glassfish.jersey.internal.Errors$1.call(Errors.java:203)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:251)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:233)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:203)
      at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
      at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:190)
      at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:865)
      at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:329)
      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:372)
      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:335)
      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:218)
      at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
      at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:175)
      at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
      at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
      at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
      at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
      at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
      at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
      at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
      at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
      at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
      at java.lang.Thread.run(Thread.java:722)
      Caused by: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB
      at com.sun.ejb.containers.StatelessSessionContainer$SessionContextFactory.create(StatelessSessionContainer.java:700)
      at com.sun.ejb.containers.util.pool.NonBlockingPool.getObject(NonBlockingPool.java:246)
      at com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:430)
      ... 56 more
      Caused by: javax.ejb.CreateException: Could not create stateless EJB
      at com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(StatelessSessionContainer.java:514)
      at com.sun.ejb.containers.StatelessSessionContainer.access$000(StatelessSessionContainer.java:97)
      at com.sun.ejb.containers.StatelessSessionContainer$SessionContextFactory.create(StatelessSessionContainer.java:698)
      ... 58 more
      Caused by: A MultiException has 1 exceptions. They are:
      1. org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at Injectee(requiredType=Logger,parent=NotWorkingStateless,qualifiers={}),position=-1,optional=false,self=false,unqualified=null,1665834801)
      at org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:74)
      at org.jvnet.hk2.internal.Utilities.justInject(Utilities.java:771)
      at org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:780)
      at org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:770)
      at org.glassfish.jersey.gf.ejb.EjbComponentInterceptor.inject(EjbComponentInterceptor.java:69)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCallback(SystemInterceptorProxy.java:133)
      at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.init(SystemInterceptorProxy.java:120)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at com.sun.ejb.containers.interceptors.CallbackInterceptor.intercept(InterceptorManager.java:986)
      at com.sun.ejb.containers.interceptors.CallbackChainImpl.invokeNext(CallbackChainImpl.java:71)
      at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:412)
      at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:375)
      at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:1967)
      at com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(StatelessSessionContainer.java:507)
      ... 60 more
      Caused by: org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at Injectee(requiredType=Logger,parent=NotWorkingStateless,qualifiers={}),position=-1,optional=false,self=false,unqualified=null,1665834801)
      ... 81 more

      Injection without Jersey/@Path works nicely. So I am unsure if this is a Jersey Issue or an EJB Container issue.

      The code is here:
      https://www.dropbox.com/s/9eqb2ji5tk6oz2y/inject-logger.zip

        Activity

        Hide
        Jakub Podlesak added a comment -

        Thanks for the nice reproducible test case.

        Just checked against a freshly built GF that has Jersey 2.0-rc1 integrated.
        There the injection works just fine and the following is written into the GF server.log
        when accessing http://localhost:8080/inject-logger-1.0-SNAPSHOT/webresources/person :

        [2013-03-26T17:34:38.931+0100] [glassfish 4.0] [INFO] [] [org.glassfish.jersey.server.ApplicationHandler] [tid: _ThreadID=26 _ThreadName=http-listener-1(1)] [timeMillis: 1364315678931] [levelValue: 800] [[
          Initiating Jersey application, version Jersey: 2.0-rc1 2013-03-26 02:00:32...]]
        
        [2013-03-26T17:34:38.988+0100] [glassfish 4.0] [WARNING] [] [org.glassfish.jersey.internal.Errors] [tid: _ThreadID=26 _ThreadName=http-listener-1(1)] [timeMillis: 1364315678988] [levelValue: 900] [[
          The following warnings have been detected: HINT: A HTTP GET method, public void net.eisele.inject.logger.NotWorkingStateless.doWork(), returns a void type. It can be intentional and perfectly fine, but it is a little uncommon that GET method returns always "204 No Content".
        ]]
        
        [2013-03-26T17:35:14.355+0100] [glassfish 4.0] [INFO] [] [NotWorkingStateless] [tid: _ThreadID=29 _ThreadName=http-listener-1(4)] [timeMillis: 1364315714355] [levelValue: 800] [[
          Not Working]]
        

        Please feel free to re-open, if you
        are able to reproduce with the next GF promoted build.

        Show
        Jakub Podlesak added a comment - Thanks for the nice reproducible test case. Just checked against a freshly built GF that has Jersey 2.0-rc1 integrated. There the injection works just fine and the following is written into the GF server.log when accessing http://localhost:8080/inject-logger-1.0-SNAPSHOT/webresources/person : [2013-03-26T17:34:38.931+0100] [glassfish 4.0] [INFO] [] [org.glassfish.jersey.server.ApplicationHandler] [tid: _ThreadID=26 _ThreadName=http-listener-1(1)] [timeMillis: 1364315678931] [levelValue: 800] [[ Initiating Jersey application, version Jersey: 2.0-rc1 2013-03-26 02:00:32...]] [2013-03-26T17:34:38.988+0100] [glassfish 4.0] [WARNING] [] [org.glassfish.jersey.internal.Errors] [tid: _ThreadID=26 _ThreadName=http-listener-1(1)] [timeMillis: 1364315678988] [levelValue: 900] [[ The following warnings have been detected: HINT: A HTTP GET method, public void net.eisele.inject.logger.NotWorkingStateless.doWork(), returns a void type. It can be intentional and perfectly fine, but it is a little uncommon that GET method returns always "204 No Content" . ]] [2013-03-26T17:35:14.355+0100] [glassfish 4.0] [INFO] [] [NotWorkingStateless] [tid: _ThreadID=29 _ThreadName=http-listener-1(4)] [timeMillis: 1364315714355] [levelValue: 800] [[ Not Working]] Please feel free to re-open, if you are able to reproduce with the next GF promoted build.

          People

          • Assignee:
            Unassigned
            Reporter:
            myfear
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: