我正在阅读this链接,但我有疑问。在这里,我们定义了方面将被调用的位置,例如@Pointcut("execution(* com.tutorialspoint.*.*(..))")
。但是,如果我们要激发我明确提到方面或注释的方面,你会怎么做?例如,在类的特定方法中,如果我们使用某个注释进行注释,则应该在spring中调用类似于@Transaction
的特定方面。怎么做类似的事情。感谢。
答案 0 :(得分:0)
您可能感兴趣的有两个可注释的点:类和/或方法。
如果您对具有特定注释的班级感兴趣,可以使用@within(SomeAnnotationType)
或within(@SomeAnnotationType *)
。将其与执行相结合,挑选出带注释的类型execution(* *(..)) && @within(SomeAnnotationType)
如果您对要注释的特定方法感兴趣,可以使用@Pointcut("execution(@SomeAnnotationType * *.*(..))")
。在这种情况下,类型是否注释无关紧要。请参阅方法签名前面的注释。
你当然可以将这两者结合起来,就像Spring一样:
pointcut executionOfMethodInAnnotatedType:
execution(* *(..)) && @within(MyAnnotation);
pointcut executionOfAnnotatedMethod():
execution(@MyAnnotation * *(..));
pointcut executionOfInterestingMethod():
executionOfMethodInAnnotatedType() ||
executionOfAnnotatedMethod();