gpt4 book ai didi

java - 具有 super 方法调用的继承方法的切入点

转载 作者:行者123 更新时间:2023-12-01 21:24:17 25 4
gpt4 key购买 nike

我有以下类(class)

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 进行切入点。如果是这样,有哪些有效的解决方法?

我尝试使用注释获取切入点,但它也不起作用。

最佳答案

1 如果有疑问,请始终退回到完全硬编码的切入点并再次继续:

execution(private void helpMe())

你确定是using AspectJ而不是普通的 Spring AOP(它不能建议私有(private)方法)?


仅供引用:https://www.eclipse.org/aspectj/doc/next/progguide/language-joinPoints.html

the call join point does not capture super calls to non-static methods

...这不适用于执行

关于java - 具有 super 方法调用的继承方法的切入点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58836455/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com