I have an application which contains an Embedded Jetty instantiated by a main application context. In Jetty there’s an additional Spring web application context initialized and a service is exported using HTTP Invoker.
Currently when the embedded context fails to initialize (by DispatcherSerlvet) the web application context is simply unavailable, but Jetty continues to run on the specified port. This makes the application inconsistent. I like to somehow tear down the main context (and the application) if the embedded Spring context fails to start. What is the correct way to do this? Is there any listener for DispatcherServlet to get notified about initialization problems?
I have an application which contains an Embedded Jetty instantiated by a main application
Share
I’ve managed to solve this on my own.
Jetty’s
ServletHolderandWebAppContextclasses now have agetUnavailableException()function which returns the initialization error or null if startup was successful. See the JETTY-319 feature request ticket. I’ve added an ID to theServletHolderbean which manages Spring’sDispatcherServletand after the refresh of the outer Spring context i’ve added a simple check against this bean. On an error i can tear down the application as i like to.