Results 1 to 2 of 2

Thread: XmlWebApplicationContext not getting ContextClosedEvent

  1. #1
    Join Date
    May 2008
    Posts
    153

    Default XmlWebApplicationContext not getting ContextClosedEvent

    I am trying to deploy my spring application within jetty. When jetty starts, ApplicationLifecycleListener beans get a ContextRefreshedEvent. However, when I stop the jetty Server, I don't get any ContextClosedEvent.

    I'm trying to understand the linkage between the web container (jetty) and springs XmlWebApplicationContext. I clearly have to do something, but is that something:
    • make my WebApplicationContext aware of jetty?
      OR
    • make jetty aware of my spring WebApplicationContext?

    And how?

    I'm actually instantiating jetty as a bean, using spring and then launching it using some java code which gets called from a windows service:
    Code:
    <bean id="myAppContext" class="org.eclipse.jetty.webapp.WebAppContext">
      <property name="contextPath" value="/myapp" />
      <property name="war" value="${my.warfile}" />
      <property name="extraClasspath" value="deploy/config" />
    </bean>
        
    <bean id="jettyServer" class="org.eclipse.jetty.server.Server">
      <property name="handler" ref="myAppContext" />
      <property name="gracefulShutdown" value="500" />
      <property name="stopAtShutdown" value="true" />
    </bean>
    From the windows service I do:
    Code:
    ClassPathXmlApplicationContext jettyCtx = new ClasspathApplicationContext(...);
    Server jettyServer = (Server)jettyCtx.getBean("jettyServer");
    jettyServer.start();
    ...
    jettyServer.stop();

  2. #2
    Join Date
    May 2008
    Posts
    153

    Default

    Figured it out after some intense reading of the jetty source:
    • Jetty does not expect to be shutdown via Server.stop() as most people would expect. Instead one is expected to call System.exit() and trigger the jetty internal Shutdown handler; so ... ShutdownHandler.getInstance().run() is the _proper_ way to shutdown handler if you are not using the VM exit (which we are not since we run from a windows service).
    • If you run any method from a daemon thread, and there are no more non-daemon threads in the VM, you should not expect any calls (like Server.stop() or WebContext.stop() to finish.

Posting Permissions

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