SpringAopImplement_1_3
스프링 AOP 구현 - V1
@Aspect 사용
@Slf4j
@Aspect
public class AspectV1 {
@Around("execution(* hello.aop.order..*(..))")
public Object doLog(ProceedingJoinPoint joinPoint) throws Throwable {
log.info("[log] {}", joinPoint.getSignature());
return joinPoint.proceed();
}
}@Slf4j
@SpringBootTest
@Import(AspectV1.class)//추가
public class AopTest {
@Autowired OrderService orderService;
@Autowired OrderRepository orderRepository;
@Test
void aopInfo() {
log.info("isAopProxy, orderService={}", AopUtils.isAopProxy(orderService));//true
log.info("isAopProxy, orderRepository={}", AopUtils.isAopProxy(orderRepository));//true
}
@Test
void success() {
orderService.orderItem("itemA");
}
@Test
void exception() {
assertThatThrownBy(() -> orderService.orderItem("ex"))
.isInstanceOf(IllegalStateException.class);
}
}
스프링 AOP 구현 - V2
포인트컷 분리
스프링 AOP 구현 - V3
어드바이스 추가

Last updated