I know this is a very old question, but I just wanted to document my findings. Can anyone confirm if they are correct? On this page, it has already been mentioned that the Spring documentation says that annotation execution is undefined if @Order annotation is not used. I tried to rename the Aspect classes and checked many times, and found that the Aspect classes are executed in alphabetical order of their names and find that the result is consistent.
The following is sample code:
@Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface A {} @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface B {} @Aspect public class A_Aspect { @Around("@annotation(mypackage.A)") public void around(ProceedingJoinPoint joinPoint) { System.out.println("A_Aspect"); joinPoint.proceed(); } } @Aspect public class B_Aspect { @Around("@annotation(mypackage.B)") public void around(ProceedingJoinPoint joinPoint) { System.out.println("B_Aspect"); joinPoint.proceed(); } } class AdvisedClass{ @B @A public void advisedMethod(){} }
When I tried to execute advisedMethod (), the following logs I received:
A_Aspect B_Aspect
I changed the annotation declaration sequence:
@A @B public void advisedMethod(){}
The following are the logs:
A_Aspect B_Aspect
I renamed @A Annotation to @C, The following are the logs:
A_Aspect B_Aspect
But, when I tried to rename the Aspect class A_Aspect to C_Aspect, the following logs:
B_Aspect C_Aspect
As I said, I want someone to confirm this, since I could not find any documentation for this
Atul kumbhar
source share