2017-08-30 58 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>