[英]Pointcut for Inherited methods with super method calls
I have the following classes我有以下课程
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();
}
}
So I want to do something everytime helpMe
method is called.所以我想在每次
helpMe
方法时做一些事情。 A.helpMe()
is never called explicitly. A.helpMe()
永远不会被显式调用。 All of the method calls for A.helpMe()
is through A.someone()
which is further called through either B.help()
or C.me()
.对
A.helpMe()
的所有方法调用都是通过A.someone()
调用的,后者通过B.help()
或C.me()
进一步调用。
helpMe
contains a common implementation that every other class needs. helpMe
包含所有其他 class 都需要的通用实现。
pointcuts I have tried我尝试过的切入点
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
I read somewhere that pointcuts
for super
is not allowed.我在某处读到不允许
super
的pointcuts
。 If thats the case, what are some valid work arounds?如果是这样,有哪些有效的解决方法?
I've tried getting pointcut
with annotations
but it does not work either.我尝试使用
annotations
获取pointcut
,但它也不起作用。
1 If in doubt, always fall back to to the fully hard-coded pointcut and work forward again: 1 如果有疑问,请始终退回到完全硬编码的切入点并再次继续工作:
execution(private void helpMe())
Are you sure you are using AspectJ and not vanilla Spring AOP (which cannot advise a private method)?您确定您使用的是 AspectJ而不是 vanilla Spring AOP(不能建议私有方法)吗?
FYI: https://www.eclipse.org/aspectj/doc/next/progguide/language-joinPoints.html仅供参考: https://www.eclipse.org/aspectj/doc/next/progguide/language-joinPoints.html
the
call
join point does not capture super calls to non-static methodscall
加入点不捕获对非静态方法的超级调用
... which is not not applicable to execution
. ...这不适用于
execution
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.