keep-alive configurations of spring-boot app
Solution 1:
Not all tomcat properties can be configured via the properties file. The keep-alive
related properties are one of those properties and that means they can only be configured programmatically. This is done by configuring a WebServerFactoryCustomizer
bean. You can use the protocol handler to set the KeepAlive
settings. An example below:
@Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> tomcatCustomizer() {
return (tomcat) -> tomcat.addConnectorCustomizers((connector) -> {
if (connector.getProtocolHandler() instanceof AbstractHttp11Protocol) {
AbstractHttp11Protocol<?> protocolHandler = (AbstractHttp11Protocol<?>) connector
.getProtocolHandler();
protocolHandler.setKeepAliveTimeout(80000);
protocolHandler.setMaxKeepAliveRequests(500);
protocolHandler.setUseKeepAliveResponseHeader(true);
}
});
}
To know more about these settings please read the tomcat 9 configuration reference