简体   繁体   English

如何在从“超级”接口扩展的接口方法上创建方面

[英]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.

相关问题 抽象超类中实现的超级接口方法的方面 - Aspect on super interface method implemented in abstract super class 如何从可扩展的类创建实例并实现通用接口? - how to create an instance from a class that extends comparable and implement generic interface? 如何在接口实例中调用超级方法? - How to call super method in interface instance? 如何使超级接口方法无效 - How to invalidate a super-interface method 从界面的默认方法中访问超级方法 - Accessing super method from within a default method in an interface 如何模拟扩展另一个接口的接口 - How to mock an interface which extends another interface 如何覆盖Iterable <interface> 将类型方法转换为Iterable <? extends interface> 返回类型方法 - How do I Override a Iterable<interface> return type method into Iterable<? extends interface> return type method 如何在扩展Parcelable的界面内部创建CREATOR? - How to Create CREATOR inside interface which extends Parcelable? 如何创建一个扩展两个其他接口的接口以在 java 中定义类型 - How to create an Interface that extends two other Interfaces to define type in java 如何为扩展JDialog的类(或通常的其他类)创建接口 - How to create an Interface for a class that extends JDialog (or in general another class)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM