[英]Pointcut for Inherited methods with super method calls
我有以下課程
class A {
public void someone() {
helpMe();
}
private void helpMe() {
// do something here
}
}
class B extends A {
public void help() {
super.someone();
}
}
class C extends A {
public void me() {
super.someone();
}
}
所以我想在每次helpMe
方法時做一些事情。 A.helpMe()
永遠不會被顯式調用。 對A.helpMe()
的所有方法調用都是通過A.someone()
調用的,后者通過B.help()
或C.me()
進一步調用。
helpMe
包含所有其他 class 都需要的通用實現。
我嘗試過的切入點
execution(* A.helpMe(..)) // does not work
execution(* A+.helpMe(..)) // does not work
execution(* *.helpMe(..)) // does not work
execution(* A.*(..)) // does not work
execution(* B.someone(..)) // does not work
execution(* A+.*(..)) // forms a point cut for B.help() and C.me() only
execution(* *.*(..)) // forms a point cut for B.help() and C.me() only
execution(* B.*(..)) // forms a point cut for B.help() only
我在某處讀到不允許super
的pointcuts
。 如果是這樣,有哪些有效的解決方法?
我嘗試使用annotations
獲取pointcut
,但它也不起作用。
1 如果有疑問,請始終退回到完全硬編碼的切入點並再次繼續工作:
execution(private void helpMe())
您確定您使用的是 AspectJ而不是 vanilla Spring AOP(不能建議私有方法)嗎?
僅供參考: https://www.eclipse.org/aspectj/doc/next/progguide/language-joinPoints.html
call
加入點不捕獲對非靜態方法的超級調用
...這不適用於execution
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.