You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
스프링 AOP 구현
OrderRepository
OrderService
AopTest
실행 - success()

스프링 AOP 구현1 - 시작
참고
실행 - sucess()

스프링 AOP 구현2 - 포인트컷 분리
AspectV2
@Pointcut@Pointcut에 포인트컷 표현식을 사용한다.@Around어드바이스에서는 포인트컷을 직접 지정해도 되지만, 포인트컷 시그니처를 사용해도 된다. 여기서는@Around("allOrder()")를 사용한다.결과적으로 AspectV1 과 같은 기능을 수행한다. 이렇게 분리하면 하나의 포인트컷 표현식을 여러 어드바이스에서 함께 사용할 수 있다. 그리고 뒤에 설명하겠지만 다른 클래스에 있는 외부 어드바이스에서도 포인트컷을 함께 사용할 수 있다.
AopTest - 수정
실행 - success()

스프링 AOP 구현3 - 어드바이스 추가
트랜잭션 기능은 보통 다음과 같이 동작
AspectV3
@Around("allOrder() && allService()")포인트컷이 적용된 AOP 결과는 다음과 같음
orderService:doLog(),doTransaction()어드바이스 적용orderRepository:doLog()어드바이스 적용AopTest - 수정
실행 - success()

AOP 적용 전
클라이언트 -> orderService.orderItem() -> orderRepository.save()
AOP 적용 후
클라이언트 -> [ doLog() doTransaction() ] -> orderService.orderItem() -> [ doLog() ] orderRepository.save()
orderService에는doLog(),doTransaction()두가지 어드바이스가 적용되어 있고,orderRepository에는doLog()하나의 어드바이스만 적용된 것을 확인할 수 있다.실행 - exception()
간을 제외하고 측정하고 싶다면 [ doTransaction() doLog() ] 이렇게 트랜잭션 이후에 로그를 남겨야 할 것이다.
Beta Was this translation helpful? Give feedback.
All reactions