Spring boot maven plugin stop goal fails to stop the application and leaves the application process hanging (and I and cannot start another process using the same port). This is the plugin configuration I have:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.6.RELEASE</version>
<configuration>
<jvmArguments>-DCONFIG_ENVIRONMENT=functionaltest</jvmArguments>
<mainClass>...</mainClass>
<fork>true</fork>
</configuration>
<executions>
<execution>
<id>start-service</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-service</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
I can't find any reference to a bug causing this behaviour. Am I using the plugin in a way it was not meant to be used maybe?
I found the problem: the spring boot application (in its main thread) starts a new thread that prevents the jvm from shutting down. Changing the "child" thread to be a daemon thread solved the issue.
Code with issue
private ExecutorService executorService = Executors.newSingleThreadExecutor(r -> {
Thread t = new Thread(r);
return t;
});
Code that solved the issue
private ExecutorService executorService = Executors.newSingleThreadExecutor(r -> {
Thread t = new Thread(r);
t.setDaemon(true);
return t;
});
Check out this SO question for more details about daemon thrreads in Java.