Skip to content

How to disable Keep alive in SpringBoot application in docker image

We have a Web application with following technologies: Java, SpringBoot, Docker, Microservices, Jhipster. The port number for the frontend container is 80.

I am trying to disable keep alive option for the frontend microservice because SSO Authentication Server requires this parameter set to be false.

I tried to create the front container with maven : mvn -Pqpm,no-liquibase -Dhttp.keepAlive=false clean verify jib:dockerBuild

I also tried to disable in pom.xml of the front container :


But the keep-alive option remains enabled when I send a http request :

Connecting to||:80... connected.
HTTP request sent, awaiting response... 
  HTTP/1.1 200 OK
  Date: Mon, 06 Apr 2020 21:14:50 GMT
  Server: Apache
  Last-Modified: Fri, 21 Oct 2016 08:42:15 GMT
  ETag: "4107-84-53f5c04e1c7c0"
  Accept-Ranges: bytes
  Content-Length: 132
  Cache-Control: max-age=0, no-store
  Keep-Alive: timeout=15, max=100
  Connection: Keep-Alive
  Content-Type: text/html
Length: 132 [text/html]
Saving to: `/dev/null'

     0K                                                       100% 15.7M=0s

2020-04-06 23:14:50 (15.7 MB/s) - `/dev/null' saved [132/132]

My Springboot config:

<!-- Dependency versions -->
<!-- The spring-boot version should match the one managed by${jhipster-dependencies.version} -->

Could you please help me to disable it ?



I finally found a solution. The way we did this was to implement a filter and add this filter to SecurityConfig.config method.

    public class KeepAliveFilter implements Filter {
        public void init(final FilterConfig filterConfig) { }

        public void destroy() { }

        public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
            final HttpServletResponse httpResponse = (HttpServletResponse) response;
            httpResponse.setHeader("Connection", "close");
            chain.doFilter(request, response);

    private final KeepAliveFilter keepAliveFilter;

    public SecurityConfiguration(final KeepAliveFilter keepAliveFilter, ...) 
        this.keepAliveFilter = keepAliveFilter;
    // other property

    protected void configure(HttpSecurity http) throws Exception {
            .addFilterBefore(corsFilter, CsrfFilter.class)
            .addFilterBefore(keepAliveFilter, CsrfFilter.class)
User contributions licensed under: CC BY-SA
4 People found this is helpful