Spring - AOP with @AspectJ

보기·2022년 10월 19일
0

Spring

목록 보기
1/1
post-custom-banner

AspectJ Order

AspectJ Annotation Order

공식 문서 - Spring 5.2.7
@Around -> @Before -> @After ->@AfterReturning -> @AfterThrowing

As of Spring Framework 5.2.7, advice methods defined in the same @Aspect class that need to run at the same join point are assigned precedence based on their advice type in the following order, from highest to lowest precedence: @Around, @Before, @After, @AfterReturning, @AfterThrowing. Note, however, that an @After advice method will effectively be invoked after any @AfterReturning or @AfterThrowing advice methods in the same aspect, following AspectJ’s "after finally advice" semantics for @After.

실행 순서와 관련된 Issue

Github issue

PR #24673 highlights a use case where AspectJPrecedenceComparator fails to assign the highest precedence to an @After advice method (declared last in the source code). Note that an @After advice method with a precedence higher than @AfterReturning and @AfterThrowing advice methods in the same aspect will effectively be invoked last due to the try-finally implementation in AspectJAfterAdvice.invoke(MethodInvocation) which invokes proceed() in the try-block and invokeAdviceMethod() in the finally-block.

profile
하루를 나답게
post-custom-banner

0개의 댓글