我有一个类似于以下问题: 如何在从“超级”接口扩展的接口方法上创建方面 ,但我的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方法放入ServiceImpl时会触发它,但不会在SuperServiceImpl触发它。 我在周围的切入点中缺少什么?
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.
The structure is as follows -
Interfaces:
public interface SuperServiceInterface { ReturnObj save(ParamObj); } public interface ServiceInterface extends SuperServiceInterface { ... }Implementations:
public abstract class SuperServiceImpl implements SuperServiceInterface { public ReturnObj save(ParamObj) { ... } } public class ServiceImpl implements ServiceInterface extends SuperServiceImpl { ... }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 { }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?
最满意答案
我只想在ServiceInterface上进行切入点,如果我在SuperServiceInterface上执行此操作,它是否也会拦截同样继承自SuperServiceInterface接口上的保存调用?
是的,但您可以通过将target()类型限制为ServiceInterface来避免这种情况,如下所示:
@Around("execution(* save(..)) && target(serviceInterface)") public Object pointCut(ProceedingJoinPoint thisJoinPoint, ServiceInterface serviceInterface) throws Throwable { System.out.println(thisJoinPoint); return thisJoinPoint.proceed(); }I just want to pointcut on the ServiceInterface, if I do it on SuperServiceInterface wouldn't it also intercept save calls on interfaces that also inherit from SuperServiceInterface?
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(); }
更多推荐
发布评论