Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring maxKeepAliveRequests in Spring Boot embedded Tomcat

I need to modify the maxKeepAliveRequests value in my Spring Boot Zuul gateway to a value higher than the default 100. Noting that this value is not exposed in Spring Boot's common properties list, I tried to set the property via @Configuration class instead:

@Configuration
public class DefaultConfig {
    @Bean
    public EmbeddedServletContainerFactory servletContainerFactory() {
        TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();

        factory.addConnectorCustomizers(connector ->
                ((AbstractHttp11Protocol) connector.getProtocolHandler()).setMaxKeepAliveRequests(1000));

        return factory;
    }
}

But it doesn't seem to take the desired effect. Is there a proper way for me to change Tomcat properties that are not exposed via Spring common properties?

like image 530
feicipet Avatar asked Mar 17 '17 04:03

feicipet


1 Answers

The code above has been confirmed to work. It was a silly mistake with a wrong @ComponentScan scope that caused my code not to work.

like image 112
feicipet Avatar answered Nov 10 '22 07:11

feicipet