I am new to Aspect-oriented programming. I am working on a spring-boot application with AspectJ, that has already an exception handling aspect as follows:
@Aspect
@Order(0)
public class ExceptionAspect {
public ExceptionAspect() {
}
@Pointcut("within(com.mycom.service.impl..*)")
public void applicationServicePointcut() {
}
@AfterThrowing(
pointcut = "applicationServicePointcut()",
throwing = "e"
)
public void translate(JoinPoint joinPoint, Throwable e) {
...
//EXCEPTION HANDLING LOGIC
}
}
Now I would like to add one more aspect, say NewAspect
for the same pointcut as mentioned above i.e.
"within(com.mycom.service.impl..*)"
Also I want any exception happening in the NewAspect
to be handled by the ExceptionAspect
.
In this regard, I am not able to understand, if the Order
of the new aspect should be more than the existing ExceptionAspect
or not.
The @Order
annotation or implementing the @Ordered
interface are Spring-specific and therefore only have an effect on Spring-managed components. AspectJ is a product independent of Spring. It has its own way of declaring and handling precedence:
Search the AspectJ programming guide for the terms "precedence" in general and the declare precedence
statement in particular.
While the former document explains the basics and how to declare precedence in native AspectJ syntax, please search the AspectJ 5 developer's notebook for @DeclarePrecedence
in order to learn about an annotation-syntax alternative.
P.S.: I asked whether you use native AspectJ or Spring AOP because of the ordering annotations and also because in Spring AOP one aspect cannot advise another one. So what you want is only possible in native AspectJ in the first place.