public abstract class AService<T> {
public T needsToBeAdvised(T param) {
T result = doSomething(param);
return result;
}
}
@Service
public class BService extends AService<B> {
@Override
public T needsToBeAdvised(T param) {
return super.needsToBeAdvised(param);
}
}
@Service
public class CService extends AService<C> {}
// (B & C implement an interface AType)
@Component
@Aspect
public class MyAspect {
@Pointcut("execution(* package.AService+.needsToBeAdvised(*))")
private void aNeedToBeAdvised() {}
@AfterReturning(pointcut="aNeedToBeAdvised()", returning="param")
public void interceptNeedsToBeAdvised(JoinPoint joinPoint, AType param) {
// some action
}
}
鉴于此设置:
bService.needsToBeAdvised(bParam) //is intercepted
但,
cService.needsToBeAdvised(cParam) //is NOT.
如何在不覆盖needsToBeAdvised()
in 的情况下实现这一目标CService
?
编辑:
我应该补充一点BService
,CService
它们都在同一个包中。
如果我将切入点更改为以下内容:
@Pointcut("execution(* package.CService.needsToBeAdvised(*))")
cService.needsToBeAdvised(cParam) //is still not intercepted
它起作用的唯一方法是如果我needsTobeAdvised()
覆盖CService