Spring AOP:在扩展类的行为中



我有一个注释,它将用于扩展占位符类。基本上,我们的服务将有一个实现,我们将有一种明确的扩展,它将被注释。我不确定问题出在哪里,但@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()时,我们将无法截获该切入点。

@withinAnnotation用于定义切入点所在的类。因此,请确保您的内部子句看起来像:

@within(@MyAnnotation *)

"*"用于表示任何类。这是您在示例中缺少的部分。

另一种方法是使用@annotation切入点:

@Annotation(@MyAnnotation)

官方文件:

https://www.eclipse.org/aspectj/doc/next/adk15notebook/annotations-pointcuts-and-advice.html

最新更新