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