3 Replies Latest reply on Apr 14, 2014 1:35 PM by Martin Kouba

    Access to CDI.current in WeldServlet

    John Ament Master

      I'm using Weld Servlet 2.1.2 in Tomcat 8.0.5.  I can try 7.0.53 as well.

       

      I added a change to the resteasy CdiInjectorFactory a few weeks back to use CDI.current to get a reference to the BeanManager.  Easier than worrying about JNDI.

       

      It would appear that this doesn't work, instead I get this error:

       

      java.lang.IllegalStateException: Singleton is not set. Is your Thread.currentThread().getContextClassLoader() set correctly?

      org.jboss.weld.bootstrap.api.helpers.IsolatedStaticSingletonProvider$IsolatedStaticSingleton.get(IsolatedStaticSingletonProvider.java:47)

      org.jboss.weld.Container.instance(Container.java:55)

      org.jboss.weld.Weld.getBeanManager(Weld.java:110)

      org.jboss.weld.Weld.getBeanManager(Weld.java:45)

      org.jboss.resteasy.cdi.CdiInjectorFactory.lookupBeanManagerCDIUtil(CdiInjectorFactory.java:226)

      org.jboss.resteasy.cdi.CdiInjectorFactory.lookupBeanManager(CdiInjectorFactory.java:151)

      org.jboss.resteasy.cdi.CdiInjectorFactory.<init>(CdiInjectorFactory.java:43)

      sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

      sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

      sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

      java.lang.reflect.Constructor.newInstance(Constructor.java:526)

      java.lang.Class.newInstance(Class.java:374)

      org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:148)

      org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.init(ServletContainerDispatcher.java:112)

      org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.init(HttpServletDispatcher.java:36)

      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)

      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74)

      org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)

      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)

      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1017)

      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652)

      org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:277)

      org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2451)

      org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2440)

      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

      java.lang.Thread.run(Thread.java:724)

       

      So, do I have to do something special for servlet?  I'm wondering if this might be an ordering issue.