3 Replies Latest reply on Jan 24, 2014 2:55 AM by Martin Kouba

    weld-servlet-2.1.2.Final @ Tomcat (6): which listener(s) to use?

    Lucas Ventura Carro Newbie

      Hi!

      I've been using weld-1.1.x in a Tomcat 6 for over a year, and I'm pretty happy of CDI

      A few months ago I readed about CDI-1.1 and weld-2.x, but a dependency (Seam-Framework version 3.x) made impossible the upgrade.

       

      Now, I'm doing trying to upgrade (and removing Seam) but I'm finding something weird in docs and functionality.

      First I upgraded from 1.1.10.Final to 2.0.4.Final. Following that release docs  it tolds to add the listener:

      <listener>
         <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
      </listener>
      

      As was done in previous versions. Worked like a charm

       

      Later, I upgraded to 2.1.2.Final, but now latest documentation about servlet containers says that we should use two different listeners:

      <listener>
         <listener-class>org.jboss.weld.servlet.WeldInitialListener</listener-class>
         ...
         ...
         <listener-class>org.jboss.weld.servlet.WeldTerminalListener</listener-class>
      </listener>
      

      And so I did.

      But then, Tomcat complains on deploying the webapp:

      SEVERE: Exception sending context initialized event to listener instance of class org.jboss.weld.servlet.WeldInitialListener
      java.lang.IllegalStateException: Singleton is not set. Is your Thread.currentThread().getContextClassLoader() set correctly?
              at org.jboss.weld.bootstrap.api.helpers.IsolatedStaticSingletonProvider$IsolatedStaticSingleton.get(IsolatedStaticSingletonProvider.java:47)
              at org.jboss.weld.Container.instance(Container.java:55)
              at org.jboss.weld.Weld.getBeanManager(Weld.java:110)
              at org.jboss.weld.Weld.getBeanManager(Weld.java:45)
              at org.jboss.weld.servlet.WeldInitialListener.contextInitialized(WeldInitialListener.java:85)
              at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
              at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
              at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
              at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
              at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
              at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:675)
              at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:601)
              at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
              at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
              at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
              at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
              at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
              at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
              at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
              at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
              at org.apache.catalina.core.StandardService.start(StandardService.java:525)
              at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
              at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
              at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
      

       

      I've found this reference on the exception, but is using 2.0.4, and as docs says, he is doing correctly. And I though "what if I try to use the old listener?" and....

      It works. The same in this stackoverflow question.

       

      So, what we are doing wrong? Should the old listener stay in the release if it should not be used? Or it is fine to be using that listener?

      Thanks!