I am using spring-boot 2.0.5 in combination with spring-data-rest. I would like to add AspectJ based advice to some of the default spring-data-rest CrudRepository methods like find, findAll and save.
No matter how I define the pointcuts, advice is never applied.
I am using LoadTimeWeaving (LTW) which, generally speaking, seems to be working.
Can someone shed some light on why this might be the case? Is it at all possible to completely replace spring-aop with AspectJ based AOP?
I have read the Spring documentation on AOP (AspectJ and spring-aop) as well as the howtos on using AspectJ in combination with spring-aop that I could find using google. All examples that I could find talk about adding AspectJ based advice to entity methods but not to spring-data-rest repository methods.
I could also find one very similar question here on stackoverflow (AspectJ pointcut on method in Spring CrudRepository). But that question has never been answered. Instead it's author provided a workaround for his specific problem. And that workaround does not apply to my requirements.
One of my ApsectJ pointcut definitions in "PointCuts.aj" is:
public pointcut repositoryFindMethods(): execution(* *..CrudRepository+.find*(..));
That pointcut should match all methods inside any interface/class derived from spring-data-rest's CrudRepository whose method name starts with "find" and that has any number of parameters.
Advice based on this pointcut definition is never applied/executed, e.g.:
Object around() : PointCuts.repositoryFindMethods() { .... }
will never be called.
However, advice is being applied as expected if I use spring-aop for implementation and specify the pointcut as:
@Pointcut("execution(* *..CrudRepository+.find*(..))")
public void repositoryFindMethods() {}
in "PointCuts.java" and implement advice using spring-aop style:
@Around("PointCuts.repositoryFindMethods()")
public Object aroundRepositoryFindMethods(ProceedingJoinPoint proceedingJoinPoint) { ... }
Because I do require ApsectJ to implement advice at another point in the code, I would like to implement advice for spring-data-rest CrudRepository methods based on AspectJ too.