2 Replies Latest reply on Mar 19, 2007 8:20 PM by gavin.king

    how best to workaround lack of ServletContext at Startup

    ccrouch

      So I just wanted to get suggestions for how I can workaround not having access to the ServletContext during the phase when components tagged with @Startup and @Application get created.

      Here's my use case:
      I've got a component,which needs some one-off, time consuming initialization to be run before it can be used. The component is currently a static singleton.
      In order to initialize the component I need to grab a resource using ServletContext.getResource(..). This resource is not available on the classpath.

      I'm currently using a servlet to do the initialization and making sure it runs early by putting <load-on-startup>1</load-on-startup> in the web.xml

      This all works however I would like to move away from using the static singleton approach and have the singleton component injected into my other Seam components which need it.

      The approach I've seen discussed before of just removing the @Startup annotation and have the component created lazily won't work here, since I don't want the first request being held up by the time consuming initialization that the component requires.

      Any other ideas?

      Cheers