Reputation: 85
I have made an annotation(@MethodLogger) and written an aspect over it which basically logs the timing of the method and keep storing it. So on any method on which i put that annotation it works fine But in a special use case I need to monitor an advice itself:
eg:
@MethodLogger
@Around("some function specified")
public Object method(ProceedingJoinPoint pjp) throws Throwable{
// code here
}
But this thing does not works. It never invokes my annotations aspect.
Upvotes: 1
Views: 242
Reputation: 67317
This does not work in Spring AOP, as is documented here:
Advising aspects with other aspects?
In Spring AOP, it is not possible to have aspects themselves be the target of advice from other aspects. The
@Aspect
annotation on a class marks it as an aspect, and hence excludes it from auto-proxying.
If you want to do this, you need to activate full AspectJ via LTW in Spring. Then you can target advices directly if you know their method name. There even is a special pointcut designator adviceexecution()
if you generally want to limit pointcut matching to advice execution or exclude the latter from matching via !adviceexecution()
. For more details please check the AspectJ documentation.
Upvotes: 2