From 79b6c10fe6e2725be6f3d0293200f8bda9228992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=ED=95=B8=EB=AA=A8?= Date: Sat, 4 May 2024 17:50:28 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=8A=A4=ED=94=84=EB=A7=81=20=EC=8A=A4?= =?UTF-8?q?=EC=BC=80=EC=A4=84=EB=9F=AC=20&=20AOP=20=EC=B6=A9=EB=8F=8C=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0=20(#441)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homepage/global/util/aop/ApiStatisticAop.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/keeper/homepage/global/util/aop/ApiStatisticAop.java b/src/main/java/com/keeper/homepage/global/util/aop/ApiStatisticAop.java index 536a2f1dc..76c176c92 100644 --- a/src/main/java/com/keeper/homepage/global/util/aop/ApiStatisticAop.java +++ b/src/main/java/com/keeper/homepage/global/util/aop/ApiStatisticAop.java @@ -1,5 +1,6 @@ package com.keeper.homepage.global.util.aop; +import java.lang.reflect.Proxy; import java.util.Objects; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -18,16 +19,21 @@ public class ApiStatisticAop { private final ApiStatistic apiStatistic; - /* TODO: Spring 스케줄러 메서드 실행이 안되서 주석 처리. +// TODO: Spring 스케줄러 메서드 실행이 안되서 주석 처리. @Around("execution(* javax.sql.DataSource.getConnection())") public Object getConnection(ProceedingJoinPoint joinPoint) throws Throwable { Object connection = joinPoint.proceed(); + // request scope가 아닌 경우 proxy를 타지 않고 바로 connection을 반환한다. + // ex) 스케쥴러 + if (RequestContextHolder.getRequestAttributes() == null) { + return connection; + } return Proxy.newProxyInstance( connection.getClass().getClassLoader(), connection.getClass().getInterfaces(), new ConnectionProxyHandler(connection, apiStatistic) ); - }*/ + } @Around("within(@org.springframework.web.bind.annotation.RestController *)") public Object calculateExecutionTime(final ProceedingJoinPoint joinPoint) throws Throwable {