2017-11-27 3 views
0

Windowsコマンドプロンプトから(java -jarを使用して)春の起動アプリケーションを実行し、Control-Cを押してプロセスを終了すると、次のコンソール出力が表示され、プロセスは開かれたままになります。Control-Cを押してWindowsでSpring起動アプリケーションプロセスを終了するには?

2017-11-27 20:15:22,713 INFO [Thread-11] (AnnotationConfigEmbeddedWebApplicationContext:984) - Closing org.springframework.boot[email protected]6057aebb: startup date [Mon Nov 27 20:14:22 IST 2017]; parent: org.spring[email protected]2df9b86 

次のコードを使用して、ContextClosedEventをリッスンします。

@Component 
public class ListenerClass { 
     @EventListener 
     public void handleContextClose(ContextClosedEvent event) { 
      shutdown(); // This method has System.exit(SpringApplication.exit(ctx)); inside it 
     } 
    } 

私は、上記のListenerClassに次のコードを追加してみましたが、それはこの問題を解決していない:

@EventListener 
    public void handleContextStop(ContextStoppedEvent event) { 
     shutdown(); 
    } 

私がコントロール-Cが押されたときにアプリケーションが終了する可能性がありますどのように?

答えて

0

リスナーに到達していません(デバッガを使用して確認してください)。それ以外の場合、System.exitはすべてのスレッドを強制終了しますが、それは悪い習慣です。

jvisualvmを使用してJVMに接続して実行し、^ Cをヒットしたらライブスレッドを確認する

関連する問題