From 859fd0eba8e83ffa45d562f946d4429703efdfed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=AD=E8=80=80=E9=A3=9E?= Date: Mon, 17 Oct 2022 10:08:17 +0800 Subject: [PATCH] Fix springboot fails to start via JAR --- .../jfxsupport/AbstractJavaFxApplicationSupport.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/felixroske/jfxsupport/AbstractJavaFxApplicationSupport.java b/src/main/java/de/felixroske/jfxsupport/AbstractJavaFxApplicationSupport.java index 288c753..fdb6b64 100644 --- a/src/main/java/de/felixroske/jfxsupport/AbstractJavaFxApplicationSupport.java +++ b/src/main/java/de/felixroske/jfxsupport/AbstractJavaFxApplicationSupport.java @@ -88,13 +88,16 @@ private void loadIcons(ConfigurableApplicationContext ctx) { */ @Override public void init() throws Exception { - // Load in JavaFx Thread and reused by Completable Future, but should no be a big deal. + // Load in JavaFx Thread and reused by Completable Future, but should not be a big deal. + // Provide an executor instead of using default, otherwise spring application will fail to start via JAR(mvn package) + ExecutorService executor = Executors.newSingleThreadExecutor(); defaultIcons.addAll(loadDefaultIcons()); CompletableFuture.supplyAsync(() -> - SpringApplication.run(this.getClass(), savedArgs) + SpringApplication.run(this.getClass(), savedArgs), executor ).whenComplete((ctx, throwable) -> { if (throwable != null) { LOGGER.error("Failed to load spring application context: ", throwable); + executor.shutdown(); Platform.runLater(() -> errorAction.accept(throwable)); } else { Platform.runLater(() -> { @@ -103,6 +106,7 @@ public void init() throws Exception { }); } }).thenAcceptBothAsync(splashIsShowing, (ctx, closeSplash) -> { + executor.shutdown(); Platform.runLater(closeSplash); }); }