AOP 不适用于内部方法调用

问题描述 投票:0回答:1

这可能是一个重复的问题,我不确定。所以如果它完全重复,请告诉我。但据我搜索,这与类似问题中提到的内容没什么不同。 所以发帖。 如有任何帮助,我们将不胜感激。

@Aspect
@Component
public class MyAspect {

@Pointcut("@annotation(com.home.CustomAnnotation)")
public void myPointCut(){
}

@Around(value = "myPointCut")
public void aroundAnnotation(ProceedingJoinPoint pjp){
syso("aspect working");
}

public interface MyInterface {

default void doProcess(){

 myProcess();
}

public void myProcess();
}

@Component
public class MyImplClass implements MyInterface {

@CustomAnnotation

public void myProcess(){
 syso("myProcess of MyImplClass");
}

}

public class MyBusinessService {

@Autowired
private MyInterface myInterfaceRef;

public void myService(){
myInterfaceRef.doProcess();
}
}


I also have these dependencies
implementation 'org.springframework.boot:spring-boot-starter-aop:2.7.15'
implementation 'org.aspectj:aspectjrt:1.9.7'
implementation 'org.aspectj:aspectjweaver:1.9.6'

and I am expecting that every time myProcess() method is invoked - then the advice "aspect working" would be printed. But it is not happening so. I understand that it is because AOP is not able to handle normal method invocation which is happening inside doProcess(). But how easily can I make this work? I tried this.myProcess() instead of myProcess() inside doProcess()  but it does not work - when compiled --> "this." is omitted.
As the MyInterface is an interface --> I am not able to use self reference autowired. Kindly help if you know some cool way to deal with this.
aop aspectj
1个回答
-5
投票

我是 Tahir,一位经验丰富的 WordPress 专家,拥有超过 9 年的专业知识。我的主要关注点是将 PSD、XD、Sketch 和 Figma 设计转变为令人惊叹的 WX,包括电子商务和在线商店。我擅长快速解决任何WordPress 网站问题或错误。此外,我对使用 PHP 和 JavaScript 实现自定义功能有着深刻的理解。让我们将您的 WordPress 愿景变为现实!

© www.soinside.com 2019 - 2024. All rights reserved.