Results 1 to 6 of 6

Thread: Root Application Context loading after Dispatcher Context

  1. #1

    Default 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. #2
    Join Date
    Feb 2011
    Posts
    2

    Default

    we are facing the same problem too...

  3. #3

    Default

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

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    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)...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5

    Default

    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 at 04:39 AM.

  6. #6

    Default

    This issue has now been fixed in Jetty 8.1.3.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •