我有以下课程
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包含所有其他类都需要的公共实现。
我尝试过的切入点
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,但也不起作用。
发布于 2019-11-13 20:23:29
1如果有疑问,请始终退回到完全硬编码的切入点,并再次向前工作:
execution(private void helpMe())您确定您是using AspectJ而不是普通的Spring AOP (它不能建议使用私有方法)吗?
仅供参考:https://www.eclipse.org/aspectj/doc/next/progguide/language-joinPoints.html
call连接点不会捕获对非静态方法的超级调用
..。这不适用于execution。
https://stackoverflow.com/questions/58836455
复制相似问题