From a1186aee9e8e32a7b7267f10173f27592d8bc80d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8E=E1=85=AC=E1=84=89=E1=85=AE=E1=84=8B=E1=85=AF?= =?UTF-8?q?=E1=86=AB?= Date: Wed, 8 May 2024 14:40:03 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20AsyncExceptionHandler=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dodamapi/common/async/AsyncConfig.java | 9 ++++++++- .../common/async/AsyncExceptionHandler.java | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 dodam-api/src/main/java/b1nd/dodamapi/common/async/AsyncExceptionHandler.java diff --git a/dodam-api/src/main/java/b1nd/dodamapi/common/async/AsyncConfig.java b/dodam-api/src/main/java/b1nd/dodamapi/common/async/AsyncConfig.java index c4471aa5..a6fd032f 100644 --- a/dodam-api/src/main/java/b1nd/dodamapi/common/async/AsyncConfig.java +++ b/dodam-api/src/main/java/b1nd/dodamapi/common/async/AsyncConfig.java @@ -1,8 +1,10 @@ package b1nd.dodamapi.common.async; +import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; +import org.springframework.scheduling.annotation.AsyncConfigurer; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; @@ -11,7 +13,7 @@ @Configuration @EnableAsync -class AsyncConfig { +class AsyncConfig implements AsyncConfigurer { @Bean @Primary @@ -26,4 +28,9 @@ public Executor asyncExecutor() { return executor; } + @Override + public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { + return new AsyncExceptionHandler(); + } + } diff --git a/dodam-api/src/main/java/b1nd/dodamapi/common/async/AsyncExceptionHandler.java b/dodam-api/src/main/java/b1nd/dodamapi/common/async/AsyncExceptionHandler.java new file mode 100644 index 00000000..77610dff --- /dev/null +++ b/dodam-api/src/main/java/b1nd/dodamapi/common/async/AsyncExceptionHandler.java @@ -0,0 +1,20 @@ +package b1nd.dodamapi.common.async; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; + +import java.lang.reflect.Method; + +@Slf4j +public class AsyncExceptionHandler implements AsyncUncaughtExceptionHandler { + + @Override + public void handleUncaughtException(Throwable ex, Method method, Object... params) { + log.error("message : " + ex.getMessage()); + log.error("method : " + method); + for(Object param : params) { + log.error("param : " + param); + } + } + +}