조인포인트란?
-> Spring AOP에서 Advide가 적용될 수 있는 지점(메서드 실행 시점)
JoinPoint객체로부터 얻을 수 있는 정보들메서드 정보
@Before("@annotation(SomeAnnotation)")
public void beforeAdvice(JoinPoint joinPoint) {
// 메서드 시그니처 정보
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
System.out.println("메서드명: " + method.getName());
System.out.println("반환타입: " + method.getReturnType());
System.out.println("메서드 선언 클래스: " + method.getDeclaringClass());
}
파라미터 정보
public void beforeAdvice(JoinPoint joinPoint) {
// 메서드에 전달된 실제 인수들
Object[] args = joinPoint.getArgs();
for (int i = 0; i < args.length; i++) {
System.out.println("파라미터 " + i + ": " + args[i]);
System.out.println("타입: " + args[i].getClass().getName());
}
// 파라미터 정보 (어노테이션 포함)
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Parameter[] parameters = signature.getMethod().getParameters();
for (Parameter param : parameters) {
System.out.println("파라미터명: " + param.getName());
System.out.println("파라미터 타입: " + param.getType());
// 어노테이션 확인
CookieValue cookieValue = param.getAnnotation(CookieValue.class);
if (cookieValue != null) {
System.out.println("쿠키값: " + cookieValue.value());
}
}
}
ProceedingJoinPoint:원본 메서드를 직접 실행할 수 있는 기능이 추가된 JoinPoint
일반 JoinPoint: 원본 메서드를 실행할 때마다 특정 시점에서 트리거되어 추가 작업 수행
@Before → 원본 메서드 실행 전에 트리거
@After → 원본 메서드 실행 후에 트리거
@Around → 컴파일 에러 (ProceedingJoinPoint 전용)
@Before("@annotation(SomeAnnotation)")
public void beforeAdvice(JoinPoint joinPoint) {
// 실행 로직
// 실행이 끝난 후 자동으로 원본 메서드 실행 (After는 순서 반대)
// 일반 JoinPoint는 Around에 붙을 수 없음(컴파일 에러)
}
ProceedingJoinPoint: 원본 메서드에 대한 실행 제어권을 완전히 위임받음(조건부 실행, 파라미터 수정 등…)
@Around에만 붙을 수 있음