I have prepared an example of mixed AOP advices ordering which can demonstrate that ordering is not applied cross @Before and @After advices.
Just run example.OrderingDemoTest
To change ordering it is enough to play with numbers in example.aop.CheckPrecedence
To see the problem, just uncomment the line with throw new RuntimeException in example.aop.CheckBeforeAspect
As I have debugged the problem is in org.springframework.aop.aspectj.autoproxy.AspectJP recedenceComparator (code snippet):
Code:
boolean oneOrOtherIsAfterAdvice =
(AspectJAopUtils.isAfterAdvice(advisor1) || AspectJAopUtils.isAfterAdvice(advisor2));
boolean oneOrOtherIsBeforeAdvice =
(AspectJAopUtils.isBeforeAdvice(advisor1) || AspectJAopUtils.isBeforeAdvice(advisor2));
if (oneOrOtherIsAfterAdvice && oneOrOtherIsBeforeAdvice) {
return NOT_COMPARABLE;
}
So the question is:
- is this the error or the intention? why this mixed Before-After ordering is disabled by extra code?
- is there any workaround available to make such situation working other than implementing advices as @Around?
Thank you if you bring some more light into this.