问题描述
我有一个非常类似于的问题:如何在从超级"继承的接口方法上创建方面接口,但是我的save方法在抽象超类中.
I have a problem quite similar to: How to create an aspect on an Interface Method that extends from A "Super" Interface, but my save method is in an abstract super class.
结构如下-
接口:
public interface SuperServiceInterface {
ReturnObj save(ParamObj);
}
public interface ServiceInterface extends SuperServiceInterface {
...
}
实施:
public abstract class SuperServiceImpl implements SuperServiceInterface {
public ReturnObj save(ParamObj) {
...
}
}
public class ServiceImpl implements ServiceInterface extends SuperServiceImpl {
...
}
我想检查对ServiceInterface.save
方法的所有调用.
I want to inspect any calls made to the ServiceInterface.save
method.
我当前拥有的切入点是这样的:
The pointcut I have currently looks like this:
@Around("within(com.xyz.api.ServiceInterface+) && execution(* save(..))")
public Object pointCut(final ProceedingJoinPoint call) throws Throwable {
}
将save方法放入ServiceImpl
时将触发该事件,但将其保存在SuperServiceImpl
中时则不会触发该事件.我的切入点缺少什么?
It gets triggered when the save method is put into the ServiceImpl
, but not when it is in the SuperServiceImpl
.What am I missing in my around pointcut?
推荐答案
是的,但是可以通过如下方式将target()
类型限制为ServiceInterface
来避免这种情况:
Yes, but you can avoid that by restricting the target()
type to ServiceInterface
as follows:
@Around("execution(* save(..)) && target(serviceInterface)")
public Object pointCut(ProceedingJoinPoint thisJoinPoint, ServiceInterface serviceInterface)
throws Throwable
{
System.out.println(thisJoinPoint);
return thisJoinPoint.proceed();
}
这篇关于抽象超类中实现的超级接口方法的方面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!