In my case I had a tomcat dependency in my pom.xml that caused the connection to be closed randomly. Check that the dependency is not included:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>