【发布时间】:2020-04-24 11:59:19
【问题描述】:
我有两节课
public class ParentTestClass {
public void publicMethodOfParent() {
}
}
@Component
@MyAnnotation
public class ChildTestClass extends ParentTestClass {
public void publicMethodOfChild() {
}
}
使用 Spring AOP 我需要包装:
- 如果注释放在类级别,则对所有使用
@MyAnnotation注释的公共方法的所有调用 - 如果注释在方法级别,则使用
@MyAnnotation注释的所有方法。
这是我的切入点
@Around("(@within(MyAnnotation) && execution(public * *(..))) || @annotation(MyAnnotation)")
public Object myWrapper(ProceedingJoinPoint invocation) throws Throwable {
// ...
}
这适用于ChildTestClass 的公共方法,但当我拨打电话childTestClass.publicMethodOfParent() 时,ParentTestClass#publicMethodOfParent 没有包装我如何包含父方法?
【问题讨论】:
-
嗯......你总是可以覆盖它。
-
是的,但是覆盖所有用法很痛苦
-
确实如此,但最终,publicMethodOfParent 是可以通过 childClass 访问的,但它并不是 childClass 的真正方法。我认为这就是区别。
标签: java aop spring-aop pointcut