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

Allow usage of existing BeanManager in a Listener

    XMLWordPrintable

Details

    Description

      I have a service where I start both Weld and Jetty in embedded mode.

      Weld is initialized in my bootloader class:

      final Weld weld = new Weld();
      WeldContainer container = weld.initialize();

      Jetty is then started by a Bean that auto-starts thanks to an extension and Annotation... So far everything works properly.

      The extension registers the BeanManager using JNDI (simple-jndi in memory) to java:comp/BeanManager (and java:comp/env/BeanManager).

      public void load(@Observes AfterDeploymentValidation event, BeanManager beanManager) {
      InitialContext ic = new InitialContext();
      ic.bind("java:comp/BeanManager", beanManager);

      My other services (resteasy-cdi) are able to query for this name and use it.

      1291 [main] DEBUG org.jboss.weld.Bootstrap - WELD-000100: Weld initialized. Validating beans
      1317 [main] INFO org.ovirt.optimizer.cdi.AutoloadExtension - Weld BeanManager for resteasy-cdi-3.0.6.Final.jar [bean count=39] registered to java:comp/BeanManager

      1570 [main] DEBUG org.jboss.resteasy.cdi.CdiInjectorFactory - Doing a lookup for BeanManager in java:comp/BeanManager
      1570 [main] DEBUG org.jboss.resteasy.cdi.CdiInjectorFactory - Found BeanManager at java:comp/BeanManager

      Unfortunately when I access any url that is handled by WeldServlet listener it boots a new Weld container and there is no way to tell it to reuse the already existing BeanManager for the sessions as well.

      Since I use beans to communicate between my "backend" and "frontend" services, it causes trouble. It initializes new copy of all the injected backend services.

      Please make it possible to tell WeldContainer (and related classes) to reuse existing Weld container instead of booting a new one.

      Attachments

        Issue Links

          Activity

            People

              mkouba@redhat.com Martin Kouba
              msivak@redhat.com Martin Sivak
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: