Java 抽象超类中实现的超接口方法

Java 抽象超类中实现的超接口方法,java,aspectj,spring-aop,pointcut,Java,Aspectj,Spring Aop,Pointcut,我的问题与:,非常类似,但我的save方法位于一个抽象的超类中 结构如下- 接口: public interface SuperServiceInterface { ReturnObj save(ParamObj); } public interface ServiceInterface extends SuperServiceInterface { ... } 实施: public abstract class SuperServiceImpl implements Sup

我的问题与:,非常类似,但我的save方法位于一个抽象的超类中

结构如下-

接口:

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
方法的所有调用

我目前的切入点如下所示:

@Around("within(com.xyz.api.ServiceInterface+) && execution(* save(..))")
public Object pointCut(final ProceedingJoinPoint call) throws Throwable {
}
当save方法放入
serviceinpl
时触发,但在
SuperServiceImpl
时不会触发。 我的环绕切入点遗漏了什么?

示例:

执行由
AccountService
接口定义的任何方法:
执行(*com.xyz.service.AccountService.*(..)

在您的情况下,它应按如下方式工作:

执行(*com.xyz.service.SuperServiceInterface.save(..)


我只想在
ServiceInterface
上切入点,如果我在
SuperServiceInterface
上切入点,它会不会在同样继承自
SuperServiceInterface
的接口上拦截save调用

是的,但是您可以通过将
target()
类型限制为
ServiceInterface
来避免这种情况,如下所示:

@Around(“执行(*save(..))&&target(serviceInterface)”)
公共对象切入点(ProceedingJoinPoint thisJoinPoint,ServiceInterface ServiceInterface)
扔掉的
{
System.out.println(此连接点);
返回此连接点。继续();
}

我只想在
服务接口
上切入点,如果我在
超级服务接口
上切入点,它不也会在同样从
超级服务接口
继承的接口上拦截save调用吗?尝试
执行(*com.xyz.service.ServiceInterface.save(..)
?这不会被拦截,可能是因为保存在接口中。我也尝试了
执行(*com.xyz.service.ServiceInterface+.save(..)
,但仍然没有触发。如果接口指定了save并且服务实现了save,那么这个切入点可以工作。我没有测试它!我将在虚拟设置中尝试它。