1

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?

UndefinedBehavior
  • 836
  • 1
  • 11
  • 20
  • Why are you using `true`? If you want the spring-boot application to be run in a forked JVM then I think you can add `true` to the `` block but it looks wrong sitting inside the `` blocks. – glytching Aug 30 '17 at 12:40
  • @glitch yes, I tried that as well. I have updated the code in the question to be like that. – UndefinedBehavior Aug 30 '17 at 14:02

2 Answers2

1

change config to this and if you want use remote debug uncomment for start app in maven run : spring-boot:stop clean spring-boot:start

<plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <configuration>
                             <executable>true</executable>
                            <fork>true</fork>
                            <addResources>true</addResources>
                            <!-- <jvmArguments> -->
                            <!-- -agentlib:jdwp=transport=dt_socket,address=localhost:5005,server=y,suspend=n -->
                            <!-- </jvmArguments> -->
                        </configuration>

                    </plugin>
ali akbar azizkhani
  • 2,213
  • 5
  • 31
  • 48
1

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.

UndefinedBehavior
  • 836
  • 1
  • 11
  • 20