From 108d4ccc95cd8d565d84f42a44dd0075d245221f Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Thu, 14 May 2020 18:04:51 +0900 Subject: [PATCH] Add web and actuator starters This commit also adds sleep to ApplicationListener.onApplicationEvent() to see if it's blocking application start-up. See https://github.com/spring-projects/spring-framework/issues/25074#issuecomment-628495503 --- build.gradle | 2 ++ .../throwaway/service/WarmUpApplicationListener.java | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/build.gradle b/build.gradle index 9e37481..8ae1c44 100644 --- a/build.gradle +++ b/build.gradle @@ -32,6 +32,8 @@ repositories { } dependencies { + implementation("org.springframework.boot:spring-boot-starter-web") + implementation("org.springframework.boot:spring-boot-starter-actuator") implementation("org.springframework.boot:spring-boot-starter-jdbc") implementation("com.h2database:h2") diff --git a/src/main/java/com/izeye/throwaway/service/WarmUpApplicationListener.java b/src/main/java/com/izeye/throwaway/service/WarmUpApplicationListener.java index 0d64df3..9e86277 100644 --- a/src/main/java/com/izeye/throwaway/service/WarmUpApplicationListener.java +++ b/src/main/java/com/izeye/throwaway/service/WarmUpApplicationListener.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.concurrent.TimeUnit; import org.springframework.boot.context.event.ApplicationStartedEvent; import org.springframework.context.ApplicationListener; @@ -25,6 +26,13 @@ public WarmUpApplicationListener(TestRepository testRepository) { public void onApplicationEvent(ApplicationStartedEvent event) { log.info("In onApplicationEvent(): {}", event); + try { + TimeUnit.SECONDS.sleep(10); + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + throw new RuntimeException(ex); + } + List ids = Arrays.asList("test1", "test2"); List threads = new ArrayList<>(); ids.forEach((id) -> {