2 Replies Latest reply on Aug 14, 2018 8:09 PM by Nicolás Lichtmaier

    Weld + Tomcat + Jerset: WELD-001304: More than one context active for scope type javax.enterprise.context.RequestScoped

    Nicolás Lichtmaier Newbie

      Hi, I'm new with all this. I'm trying to set up a project using Jersey over Tomcat. By adding Weld to the mix I was able to have a @Context ServletContext injected. But I wanted more: I wanted to inject my own objects, so I added an empty beans.xml (? - saw that somewhere) and... bang! I got this exception:

       

      org.jboss.weld.exceptions.IllegalStateException: WELD-001304: More than one context active for scope type javax.enterprise.context.RequestScoped

      at org.jboss.weld.manager.BeanManagerImpl.internalGetContext(BeanManagerImpl.java:763)

      at org.jboss.weld.manager.BeanManagerImpl.isContextActive(BeanManagerImpl.java:749)

      at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:161)

      at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:70)

      at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:100)

      at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)

      at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:785)

      at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:808)

      at org.jboss.weld.util.ForwardingBeanManager.getReference(ForwardingBeanManager.java:61)

      at org.jboss.weld.bean.builtin.BeanManagerProxy.getReference(BeanManagerProxy.java:85)

      at org.glassfish.jersey.ext.cdi1x.internal.CdiUtil.getBeanReference(CdiUtil.java:151)

      at org.glassfish.jersey.ext.cdi1x.internal.AbstractCdiBeanSupplier$1.getInstance(AbstractCdiBeanSupplier.java:93)

      at org.glassfish.jersey.ext.cdi1x.internal.AbstractCdiBeanSupplier._provide(AbstractCdiBeanSupplier.java:127)

      at org.glassfish.jersey.ext.cdi1x.internal.RequestScopedCdiBeanSupplier.get(RequestScopedCdiBeanSupplier.java:70)

      at org.glassfish.jersey.inject.hk2.InstanceSupplierFactoryBridge.provide(InstanceSupplierFactoryBridge.java:77)

      at org.jvnet.hk2.internal.FactoryCreator.create(FactoryCreator.java:153)

      at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:487)

      at org.jvnet.hk2.internal.PerLookupContext.findOrCreate(PerLookupContext.java:70)

      at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2126)

      at org.jvnet.hk2.internal.ServiceLocatorImpl.internalGetService(ServiceLocatorImpl.java:777)

      at org.jvnet.hk2.internal.ServiceLocatorImpl.internalGetService(ServiceLocatorImpl.java:740)

      at org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:710)

      at org.glassfish.jersey.inject.hk2.AbstractHk2InjectionManager.getInstance(AbstractHk2InjectionManager.java:184)

      at org.glassfish.jersey.inject.hk2.ImmediateHk2InjectionManager.getInstance(ImmediateHk2InjectionManager.java:54)

      at org.glassfish.jersey.internal.inject.Injections.getOrCreate(Injections.java:129)

      at org.glassfish.jersey.server.model.MethodHandler$ClassBasedMethodHandler.getInstance(MethodHandler.java:284)

      at org.glassfish.jersey.server.internal.routing.PushMethodHandlerRouter.apply(PushMethodHandlerRouter.java:75)

      at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:110)

      at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:113)

      at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:113)

      at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:113)

      at org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:93)

      at org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:62)

      at org.glassfish.jersey.process.internal.Stages.process(Stages.java:197)

      at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:269)

      at org.glassfish.jersey.internal.Errors$1.call(Errors.java:272)

      at org.glassfish.jersey.internal.Errors$1.call(Errors.java:268)

      at org.glassfish.jersey.internal.Errors.process(Errors.java:316)

      at org.glassfish.jersey.internal.Errors.process(Errors.java:298)

      at org.glassfish.jersey.internal.Errors.process(Errors.java:268)

      at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:289)

      at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:256)

      at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:703)

      at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:416)

      at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:370)

      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:389)

      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:342)

      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:229)

      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)

      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)

      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)

      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:491)

      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)

      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)

      at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)

      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)

      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)

      at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)

      at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)

      at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:764)

      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1388)

      at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

      at java.lang.Thread.run(Thread.java:748)

       

      (I'm not doing anything with Weld directly, I'm not manually creating any context or something).

       

      If I put a breakpoint at the time of the crash I get that the contexts (the ctx variable at the point of the crash) are instances of this classes:

       

      • org.jboss.weld.context.bound.BoundRequestContextImpl (this first one isActive and produces the crash)
      • org.jboss.weld.context.unbound.RequestContextImpl
      • org.jboss.weld.context.http.HttpRequestContextImpl

       

      I think what I'm trying to do is pretty simple, it shouldn't be so hard. I don't know if I'm hitting a bug or if I'm doing somethin wrong.

       

      Thanks!