SpringAopImplement_4_6
스프링 AOP 구현 - V4
포인트컷 참조
public class Pointcuts {
@Pointcut("execution(* hello.aop.order..*(..))")
public void allOrder(){} //포인트컷 시그니처
//클래스 이름 패턴이 *Service
@Pointcut("execution(* *..*Service.*(..))")
public void allService(){}
@Pointcut("allOrder() && allService()")
public void orderAndService(){}
}@Slf4j
@Aspect
public class AspectV4Pointcut {
@Around("Pointcuts.allOrder()")
public Object doLog(ProceedingJoinPoint joinPoint) throws Throwable {
log.info("[log] {}", joinPoint.getSignature());
return joinPoint.proceed();
}
//hello.aop.order 패키지와 하위 패키지 이면서 동시에 클래스 이름 패턴이 *Service
@Around("Pointcuts.orderAndService()")
public Object doTransaction(ProceedingJoinPoint joinPoint) throws Throwable {
try {
log.info("[트랜잭션 시작] {}", joinPoint.getSignature());
Object result = joinPoint.proceed();
log.info("[트랜잭션 커밋] {}", joinPoint.getSignature());
return result;
} catch (Exception e) {
log.info("[트랜잭션 롤백] {}", joinPoint.getSignature());
throw e;
} finally {
log.info("[리소스 릴리즈] {}", joinPoint.getSignature());
}
}
}스프링 AOP 구현 - V5
어드바이스 순서

스프링 AOP 구현 - V6
어드바이스 종류
@Before
@AfterReturning
@AfterThrowing
@After
@Around

Last updated