How to make DispatcherServlet initialization errors bubble up from embedded Jetty?
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've managed to solve this on my own. Jetty's ServletHolder and WebAppContext classes now have a getUnavailableException() 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 the ServletHolder bean which manages Spring's DispatcherServlet and 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.