Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set Tomcat unloadDelay in a Spring Boot 2 application?

The default is 2000ms which isn't enough time for requests to complete cleanly in my application.

https://tomcat.apache.org/tomcat-8.5-doc/config/context.html

like image 320
David Tinker Avatar asked Mar 29 '18 09:03

David Tinker


1 Answers

From Spring Booot 2, you can use:

@Bean
public ServletWebServerFactory servletWebServerFactory() {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.addContextCustomizers(context -> {
        if(context instanceof StandardContext) {
            ((StandardContext)context).setUnloadDelay(8000);
        }
    });
    return tomcat;
}

Before Spring Boot 2, this was different and you have to use a TomcatEmbeddedServletContainerFactory instead of the TomcatServletWebServerFactory and EmbeddedServletContainerFactory instead of ServletWebServerFactory.

like image 50
Ortomala Lokni Avatar answered Oct 16 '22 15:10

Ortomala Lokni