如何在从“超级"扩展的接口方法上创建方面界面 [英] How to create an aspect on an Interface Method that extends from A "Super" Interface

查看:21
本文介绍了如何在从“超级"扩展的接口方法上创建方面界面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从基础接口扩展而来的服务层接口;我想围绕我的服务层接口创建一个切入点,但是在基本接口中定义的方法之一上.

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.

例如......我在我的基本接口中有一个名为save()"的方法,我把它放在我的基本接口中,因为我所有的子"接口都将提供保存"功能.

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.

当我的保存"被调用时,我只想在我的一个子"界面上创建一个切入点.

I would like to create a PointCut on only one of my "child" interfaces for when my "save" gets called.

我创建的切入点如下:

@Pointcut("execution(* com.xyz.someapp.ChildServiceInterface.save(..))")  
public void childServiceSavePointCut();

然后我围绕上述切入点创建了一个@Around 建议,如下所示:

I then created a @Around advice around the above pointcut like the following:

@Around("childServiceSavePointCut()")
public void doMyAdvice()....

其中ChildServiceInterface"扩展了另一个定义了save()"方法的接口.

where "ChildServiceInterface" extends another Interface which has the "save()" method defined.

我的建议从未运行...我调试了我的代码,但在目标服务的顾问列表中没有看到我的建议.

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?

推荐答案

试试这个切入点.

within(com.xyz.someapp.ChildServiceInterface+) && execution(* save(..))

+ 表示子类型模式.

这篇关于如何在从“超级"扩展的接口方法上创建方面界面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆