문제점

스프링에서 제공하는 동적 프록시를 통합해서 편리하게 만들어주는 프록시 팩토리(ProxyFactory)기능을 사용하면 문제 해결 가능하다

Advisor = Advice + PointCut

MethodInterceptor - 스프링이 제공하는 코드

package org.aopalliance.intercept; // 패키지 주의, CGLIB와 다름

public interface MethodInterceptor extends Interceptor { // MethodInterceptor > Interceptor > Advice 상속 관계
	Object invoke(MethodInvocation invocation) throws Throwable;
}

TimeAdvice 생성

@Slf4j
public class TimeAdvice implements MethodInterceptor {
    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        log.info("TimeProxy 실행");
        long startTime = System.currentTimeMillis();

        Object result = invocation.proceed(); // target 메서드 실행

        long endTime = System.currentTimeMillis();
        long resultTime = startTime - endTime;
        log.info("result time 종료 = {}ms", resultTime);

        return result;
    }
}

프록시 팩토리 생성자에 target 정보를 파라미터로 전달하기 때문에 MethodInvocation invocation에 target 클래스 정보가 포함되어 있다고 생각하면 된다