我有两堂课
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
的公共方法,但是当我调用ParentTestClass#publicMethodOfParent
时如何不包装childTestClass.publicMethodOfParent()
?如何包含父方法?
以下切入点表达式也将拦截父方法
@Around("(@within(MyAnnotation) && execution(public * *(..))) || @annotation(MyAnnotation) || within(ParentTestClass)")
public Object myWrapper(ProceedingJoinPoint invocation) throws Throwable {
return invocation.proceed();
}
inwith:限制匹配以匹配某些类型内的连接点(使用时在匹配类型内声明的方法的执行Spring AOP)。