[英]How to create an aspect on an Interface Method that extends from A "Super" Interface
I have a service-layer Interface that extends from a base Interface;我有一个从基本接口扩展的服务层接口; I would like to create a Pointcut around my service-layer Interface, but on one of the methods defined in the base Interface.我想围绕我的服务层接口创建一个切入点,但要在基本接口中定义的方法之一上创建。
For instance.... I have a method in my base Interface called "save()", I put it in my base Interface since just all of my "child" Interfaces will provide "save" functionality.例如....我在我的基本接口中有一个名为“save()”的方法,我把它放在我的基本接口中,因为只有我所有的“子”接口都将提供“保存”功能。
I would like to create a PointCut on only one of my "child" interfaces for when my "save" gets called.当我的“保存”被调用时,我只想在我的一个“子”界面上创建一个 PointCut。
I created the pointcut like the following:我创建了如下切入点:
@Pointcut("execution(* com.xyz.someapp.ChildServiceInterface.save(..))")
public void childServiceSavePointCut();
I then created a @Around advice around the above pointcut like the following:然后,我围绕上述切入点创建了一个 @Around 建议,如下所示:
@Around("childServiceSavePointCut()")
public void doMyAdvice()....
where "ChildServiceInterface" extends another Interface which has the "save()" method defined.其中“ChildServiceInterface”扩展了另一个定义了“save()”方法的接口。
My Advice never runs... I debugged my code and do not see my Advice in the list of Advisors for my target service.我的建议从未运行...我调试了我的代码,但没有在我的目标服务的顾问列表中看到我的建议。
Am I way off base thinking this will work, or am I implementing it incorrectly?我是不是认为这会奏效,还是我实施不正确?
Try this pointcut instead. 试试这个切入点。
within(com.xyz.someapp.ChildServiceInterface+) && execution(* save(..))
The +
indicates a subtype pattern . +
表示子类型 。
Or you can put pointcut on all the methods of that class using 或者你可以使用切入点上该类的所有方法
@Pointcut("execution(* com.xyz.someapp.ChildServiceInterface.*(..))")
public void childServiceSavePointCut();
The *
indicates all method type. *
表示所有方法类型。
This one helps me:这对我有帮助:
@Pointcut(
"@within(com.xyz.someapp.ChildServiceInterface) && execution(* save(..))"
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.