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 {