Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-1517

Wrong shutdown order in Servlet listener, @Destroyed(ApplicationScoped.class) event not fired

XMLWordPrintable

      public class ObserverTest {
      
          final private static Logger log = Logger.getLogger(ObserverTest.class.getName());
      
          public void start(@Observes @Initialized(ApplicationScoped.class) Object o) throws Exception {
              log.info("### START");
          }
      
          public void stop(@Observes @Destroyed(ApplicationScoped.class) Object o) throws Exception {
              log.info("### STOP");
          }
      }
      

      The @Destroyed(ApplicationScoped.class) event is never fired. Most likely this code in org.jboss.weld.environment.servlet.Listener is wrong:

          @Override
          public void contextDestroyed(ServletContextEvent sce) {
              /* Wrong order:
      
              bootstrap.shutdown();
              if (container != null) {
                  container.destroy(new ContainerContext(sce, null));
              }
              super.contextDestroyed(sce);
               */
      
              // Workaround:
              if (container != null) {
                  container.destroy(new ContainerContext(sce, null));
              }
              super.contextDestroyed(sce);
              bootstrap.shutdown();
          }
      

              mkouba@redhat.com Martin Kouba
              christian.bauer_jira Christian Bauer (Inactive)
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: