2017-08-30 38 views
0

Spring引导maven插件停止目标无法停止应用程序,并且使应用程序进程挂起(并且我无法使用同一端口启动另一个进程)。 这是插件配置我:spring boot maven插件停止目标

 <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> 

我无法找到造成这种行为的错误任何引用。我是否以某种不适合使用插件的方式使用?

+0

为什么使用' true'?如果你想在春天启动应用程序在一个分叉JVM中运行,那么我想你可以添加'真正'的'<配置>'块,但它看起来错坐在''块中。 – glytching

+0

@ glitch是的,我也试过。我已经更新了问题中的代码。 – UndefinedBehavior

回答

1

,我发现了问题所在: spring启动应用程序(在其主线程中)启动一个新的线程,防止jvm关闭。将“子”线程更改为守护进程线程解决了问题。

代码的问题就解决了问题

 private ExecutorService executorService = Executors.newSingleThreadExecutor(r -> { 
      Thread t = new Thread(r); 
      t.setDaemon(true); 
      return t; 
     }); 

退房this SO question有关Java的守护thrreads详情

 private ExecutorService executorService = Executors.newSingleThreadExecutor(r -> { 
      Thread t = new Thread(r); 
      return t; 
     }); 

代码。

1

改变配置到这一点,如果你想在Maven的运行使用远程调试取消注释 用于启动应用程序:弹簧启动:停止清理春季启动:启动

<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> 
相关问题