이전 포스팅에서 AOP에 대해 다룬 포스팅도 있고, pointcut에 대해 다룬 글들이 있다.
자세한 내용은 아래 참고 포스팅을 참고 바란다.
예제에서는 대부분 JoinPoint 로만 설명을 했으나 ProceedingJoinPoint 에 대해서 잠시 다루려고 한다.
JoinPoint
JoinPoint 는 테스트 코드로도 많이 다뤘었고 메서드에 대해서는 아래와 같다.
(인터페이스는 호출되는 대상 객체, 메서드, 전달 파라미터 목록에 접근 할 수 있는 메소드 제공)
메서드 | 접근하는 영역 |
---|---|
Signature getSignature() |
호출되는 메서드에 대한 정보 |
Object getTarget() |
대상 객체 |
Object[] getArgs() |
파라미터 목록 |
Signature에 대해서도 아래와 같다.
(인터페이스는 호출되는 메서드와 관련된 정보를 제공)
메서드 | 접근하는 영역 |
---|---|
String getName() |
메서드 이름 |
String toLongName() |
메서드를 완전하게 표현한 문장(반환 타입, 파라미터 타입) |
String getArgs() |
파라미터 목록 |
ProceedingJoinPoint
이 객체는 일단 JoinPoint를 상속받아서 비슷한 기능을 대체한다.
하지만 좀 다른점은 Around Advice에서만 지원되는 Join Point이고
TargetObject 의 정보를 받은 후 실행을 제어할수 있다.
아래 예제를 보면
@Around("@annotation(org.springframework.web.bind.annotation.GetMapping)") public void doLog1(ProceedingJoinPoint joinPoint) throws Throwable { System.out.println(joinPoint.getSignature()); joinPoint.proceed(); } |
@Around("@annotation(org.springframework.web.bind.annotation.GetMapping)") public void doLog1(ProceedingJoinPoint joinPoint) throws Throwable { System.out.println(joinPoint.getSignature()); } |
두 코드의 차이는 proceed()가 있냐 없냐의 차이이고
있어야만 본 로직으로 돌아가서 코드를 실행시킨다.
@Around("@annotation(org.springframework.web.bind.annotation.GetMapping)") public void doLog1(ProceedingJoinPoint joinPoint) throws Throwable { System.out.println(joinPoint.getSignature()); if ("a".equals(joinPoint.getSignature()){ joinPoint.proceed(); } } |
이런식으로 특정 이름에만 돌아가도록 설정을 할수도 있다.
참고 포스팅
https://thenicesj.tistory.com/564
springboot AOP 설정하기
자바에서 aop 에 대해서 이전 포스팅에서 다룬 글이 있다. 자세한 사항은 아래 참고 포스팅 참고 바란다. 이번 포스팅에서는 springboot 에 aop 설정하는법에 대해서 다뤄 볼것이다. 개발 환경 springboo
thenicesj.tistory.com
https://thenicesj.tistory.com/565
aop pointcut 정리
저번 포스팅에서 aop 설정법에 대해서 다룬적이 있다. 자세한 내용은 아래 참고 포스팅을 참고 바란다. 사용법은 다음과 같다. 먼저 @Aspect를 선언할 클래스를 만들어준다. @Aspect @Component public class
thenicesj.tistory.com
https://thenicesj.tistory.com/566
aop pointcut 정리(추가 정리)
이전 포스팅에 이어 좀더 심화 정리를 추가하려고 한다. 1. 여러개의 execution 정의 -> 표현식을 사용한다. and 는 && , or 는 || 등을 사용하여 @Before("execution(* com..*.*(..)) && @annotation(org.apache.ibatis.annotat
thenicesj.tistory.com
'IT > Java' 카테고리의 다른 글
Java 에서 Redis 사용하기 (@RedisHash , ValueOperations) (34) | 2023.12.06 |
---|---|
java.util.Date / java.sql.Date 차이 (38) | 2023.12.05 |
Boolean, boolean 차이 (37) | 2023.11.19 |
추가 설정 파일 사용하기(properties / yml) (43) | 2023.11.17 |
@Transactional 사용시 주의 사항4 (propagation(전파속성) 에 대해) (45) | 2023.11.14 |
댓글