Closed
Description
On a plain web Spring Boot (3.0.5) application if one do context.stop()
and then context.start()
the context on a I get an error:
Exception in thread "main" org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181)
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155)
at org.springframework.context.support.DefaultLifecycleProcessor.start(DefaultLifecycleProcessor.java:103)
at org.springframework.context.support.AbstractApplicationContext.start(AbstractApplicationContext.java:1418)
at com.example.crac.springwebcrac.SpringWebCracApplication.main(SpringWebCracApplication.java:35)
Caused by: java.lang.IllegalStateException: The host does not contain a Context
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.findContext(TomcatWebServer.java:153)
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:232)
at org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:44)
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178)
To reproduce create a plain web boot application SpringWebCracApplication
like this:
public static void main(String[] args) throws InterruptedException {
ConfigurableApplicationContext context = SpringApplication.run(SpringWebCracApplication.class, args);
context.stop();
Thread.sleep(5000);
context.start();
}
It looks like the tomcat.destroy()
, called on context.stop()
, destroys the Tomcat.Context
and later is not re-created on start.
Note that If we replace the Tomcat
with a Jetty
the application works fine and recovers after stop/start.