2
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
}
}
鑑於此設置沒有覆蓋超類方法:Spring AOP的 - 建議在子類中
bService.needsToBeAdvised(bParam) //is intercepted
但是,
cService.needsToBeAdvised(cParam) //is NOT.
如何做到這一點沒有覆蓋在CService
needsToBeAdvised()
?
編輯:
我要補充一點,BService
和CService
都在同一個包。
如果我改變我的觀點切到以下幾點:
@Pointcut("execution(* package.CService.needsToBeAdvised(*))")
cService.needsToBeAdvised(cParam) //is still not intercepted
它的工作的唯一方法是,如果我在CService
感謝您的答覆。他們在同一個包裏。見上面的編輯。 – mantithetical 2012-04-08 19:28:56