1 Reply Latest reply on Apr 24, 2014 6:00 AM by jaikiran pai

    bootstrap order of container services

    Thomas Kriechbaum Newbie

      Is there a defined bootstrap order of container services when a JavaEE app gets started?

       

      I have tried to access the JNDI app namespace while processing a CDI BeforeBeanDiscovery event. But it seems that the JNDI namespace has not built up before the CDI environment gets initialized. In a CDI producer (gets invoked late in the CDI lifecycle) the JNDI lookup works fine (see source code below)

       

      Wildfly 8 and Glassfish 4 behave identically. Interestingly, with WAS 8.0.x the JNDI namespace gets initialized before the CDI environment (JNDI lookup even works in the CDI extension).

       

      Is this covered by any JavaEE specification (bootstrap order, components which can use the JNDI app namespace)?

       

      This topic is no blocker, because we can implement our configuration initialization by some other means. But it would be nice, if we can handle this within a CDI extension to influence the creation of some CDI-managed beans (veto). The URL defined in the app namespace points to the necessary configuration file.

       

      Note: Injecting URL-References requires Wildfly 8.1.0 CR1 (see Portable Naming and Binding of Resources).

       

      // JNDI lookup causes NamingException

      public class ConfigurationExtension implements Extension {


          public ConfigurationExtension() {

          }

       

          public void preloadConfiguration(@Observes BeforeBeanDiscovery event, BeanManager beanManager) {

              System.out.println("preloadConfiguration");

              try {

                  URL url = (URL) new InitialContext().lookup("java:app/env/url/configuration");

                  Configuration config = new Configuration();

                  config.setSource("before-bean-discovery");

                  config.setPath(url.toExternalForm());

              } catch (NamingException exception) {

                  exception.printStackTrace();

              }

         }

      }

       

      Resource-Injection works within the producer (could be implemented via InitalContext, too).

       

      public class ConfigurationProducer {

       

          @Resource(lookup = "java:app/env/url/configuration")

          private URL configuration;

       

          public ConfigurationProducer() {

          }

       

          @Produces

          @External

          public Configuration configuration(InjectionPoint ip) {

              Configuration config = new Configuration();

              config.setSource("cdi-producer");

              config.setPath(configuration.toExternalForm());

              return config;

          }

      }

       

      Thanks,

      Thomas