Announcement Announcement Module
Collapse
No announcement yet.
Root Application Context loading after Dispatcher Context Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Root Application Context loading after Dispatcher Context

    I am currently trying to get an application with two Servlets registered in a WebApplicationInitializer to run in Jetty 8.x.

    I am having the problem as described here. I was hoping someone could elaborate on this statement:

    Put the root context as an argument into the dispatcherContext.
    Does this mean:

    Code:
    dispatcherContext.setParent(rootContext)
    This only seems to work if I remove:

    Code:
    ContextLoaderListener listener = new ContextLoaderListener(rootContext);
    container.addListener(listener);
    and add:

    Code:
    rootContext.refresh();
    However, when I add Spring Security back in and go to a secured page I hit:

    Code:
    No WebApplicationContext found: no ContextLoaderListener registered?
    Which is of course correct!

    Can someone just point me in the right direction here? Thanks.

  • #2
    we are facing the same problem too...

    Comment


    • #3
      I really want Marten to elaborate on his statement on the linked issue. It sounds like he knows how to fix this.

      Comment


      • #4
        I don't really know how to fix it . But it was a gut feeling that you could simply pass the parent in as the parent context for either the context registered with the dispatcher servlet or by calling the setter.

        However I feel that this is more of a Jetty issue (as I tried Spring 3.1 with at least Tomcat, tcServer, JBoss and Glassfish without any problems)...

        Comment


        • #5
          Thanks for your reply. It seems likely that it's a Jetty issue since there are no problems on Tomcat 7. I was getting annoyed with this yesterday so went away and found a workaround.

          In case anyone is interested:

          Code:
          AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
          context.register(RootConfig.class);
          
          AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
          dispatcherContext.register(DispatcherConfig.class);
          dispatcherContext.setParent(context);
          
          ContextLoaderListener contextLoaderListener = new ContextLoaderListener(context);
          contextLoaderListener.contextInitialized(new ServletContextEvent(servletContext));
          
          ServletRegistration.Dynamic dispatcher =
          servletContext.addServlet("appServlet", new DispatcherServlet(dispatcherContext));
          dispatcher.setLoadOnStartup(1);
          dispatcher.addMapping("/*");
          Instead of registering my ContextLoaderListener and waiting for Jetty to invoke the ContextLoaderListener#onContextLoaded event I go ahead and invoke it myself by creating the ContextLoaded event.

          I also register the root context as the parent of the dispatcher context which is what I assume Marten was talking about

          Edit:

          I have just found this issue. The registered servlets are being instantiated before the listeners. It was fixed but still seems to be an issue in the latest version of Jetty 8.

          I have provided a link to this discussion.
          Last edited by alexbarnes; Mar 12th, 2012, 04:39 AM.

          Comment


          • #6
            This issue has now been fixed in Jetty 8.1.3.

            Comment

            Working...
            X