我有一个注释,它将用于扩展的占位符类。基本上,我们的服务将有一个实现,并且我们将有一个带注释的显式扩展。我不确定是什么问题,但是@within
没有调用代码,而@target
是。
这是示例代码-https://github.com/sahil-ag/Spring-AOP-Sample
@Component
public BaseClass { public void getData() {return "";}}
@SampleAnnotation
@Component
public DerivedClass extends BaseClass {}
如果现在使用@within(SampleAnnotation)
切入点,当从派生类Bean调用时,我们将无法拦截getData()
。
答案 0 :(得分:0)
要定义切入点所在的类时,请使用@within
注释。因此请确保您的子句如下:
@within(@MyAnnotation *)
“ *”用于表示 any 类。这是您的示例中缺少的部分。
另一种方法是使用@annotation
切入点:
@Annotation(@MyAnnotation)
官方文档:
https://www.eclipse.org/aspectj/doc/next/adk15notebook/annotations-pointcuts-and-advice.html