I use spring-aop to make some treatments on my services methods. The methods on wich the treatment must occur are annotated with @History. Moreover, the annotation can have some params like "comment". Here is on exemple :
@Service
public class MyServiceImpl implements IMyService {
@Override
@History(comment = "my comment")
public void myMethod() {...}
}
public interface IMyService {
void create();
}
And, I have a aspect defined like this :
@Aspect
@Component
public class MyHistoryAspect {
@AfterReturning(pointcut = "execution(* my.service.package.*(..)) && @annotation(history)", returning = "result")
public void myTreatment(JoinPoint joinPoint, History history, Object result) {
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
Method method = methodSignature.getMethod();
...
}
}
Now, my problem : when I use reflection to find out the value of "comment" in my aspect, I can't find it. The reason : the method is the method signature of IMyService, not the method signature of MyServiceImpl. And if I put my annotation on the interface instead of the service, my Aspect is never reached.
Am I missing something or is it the normal behavior of spring aop ?
Thank you
Aucun commentaire:
Enregistrer un commentaire