-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: 종료 시 스프링 라이프 사이클 콜백을 제대로 호출하는지 검증
- Loading branch information
Showing
5 changed files
with
137 additions
and
31 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
test/src/main/java/io/jeyong/test/cleanup/CleanupConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.jeyong.test.cleanup; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class CleanupConfiguration { | ||
|
||
@Bean | ||
public PreDestroyHandler preDestroyHandler() { | ||
return new PreDestroyHandler(); | ||
} | ||
|
||
@Bean | ||
public ContextClosedEventHandler contextClosedEventHandler() { | ||
return new ContextClosedEventHandler(); | ||
} | ||
|
||
@Bean | ||
public ShutdownHookHandler shutdownHookHandler() { | ||
ShutdownHookHandler shutdownHookHandler = new ShutdownHookHandler(); | ||
shutdownHookHandler.registerShutdownHook(); | ||
return shutdownHookHandler; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
test/src/main/java/io/jeyong/test/cleanup/ContextClosedEventHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.jeyong.test.cleanup; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.event.ContextClosedEvent; | ||
import org.springframework.context.event.EventListener; | ||
|
||
@Slf4j | ||
public class ContextClosedEventHandler { | ||
|
||
public static final String CONTEXT_CLOSED_EVENT_LOG = "Handling ContextClosedEvent..."; | ||
|
||
@EventListener(ContextClosedEvent.class) | ||
public void handleContextClosed() { | ||
log.info(CONTEXT_CLOSED_EVENT_LOG); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
test/src/main/java/io/jeyong/test/cleanup/PreDestroyHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.jeyong.test.cleanup; | ||
|
||
import jakarta.annotation.PreDestroy; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class PreDestroyHandler { | ||
|
||
public static final String PRE_DESTROY_LOG = "Executing @PreDestroy cleanup logic..."; | ||
|
||
@PreDestroy | ||
public void cleanup() { | ||
log.info(PRE_DESTROY_LOG); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
test/src/main/java/io/jeyong/test/cleanup/ShutdownHookHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.jeyong.test.cleanup; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class ShutdownHookHandler { | ||
|
||
public static final String SHUTDOWN_HOOK_LOG = "Executing JVM Shutdown Hook..."; | ||
|
||
public void registerShutdownHook() { | ||
Runtime.getRuntime().addShutdownHook(new Thread(() -> log.info(SHUTDOWN_HOOK_LOG))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters