AspectJ-接口实现方法的切入点 [英] AspectJ - pointcut for methods of interface's implementation

查看:161
本文介绍了AspectJ-接口实现方法的切入点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有SomeInterface的几种实现.问题是SomeInterface的所有实现中executeSomething方法的切入点是什么.

I have several implementations of SomeInterface. The question is what is the pointcut for the method executeSomething in all implementation of SomeInterface.

public class SomeImplementation implements SomeInterface {

    public String executeSomething(String parameter) {
        // Do something
    }

}

public class AnotherImplementation implements SomeInterface {

    public String executeSomething(String parameter) {
        // Do something different way
    }

}

推荐答案

该方法的切入点可以是方法执行切入点或方法调用切入点.您需要的最具体的切入点如下所示:

Pointcuts for that method can be either method-execution or method-call pointcuts. The most specific pointcuts for your requirement would look like this:

execution(public String SomeInterface+.executeSomething(String))
call(public String SomeInterface+.executeSomething(String))

关于这些切入点类型的一些解释:

Some explanation on these pointcut types:

  • 在这两个切入点中使用的类型模式的意思是:所有返回String的公共方法,这些方法在SomeInterface或其任何子类型中定义,被命名为executeSomething并接受单个String参数.这是可以为您的案例定义的最具体的类型模式,它将仅匹配String SomeInterface.executeSomething(String)方法的实现.
  • 执行类型切入点匹配与执行特定方法主体时相对应的连接点
  • 调用类型切入点匹配与调用特定方法时对应的连接点(即连接点位于调用方)
  • the type pattern used in both these pointcuts mean: all public methods that return String that are defined in SomeInterface or any subtype of it, being named executeSomething and accepting a single String argument. This is the most specific type pattern that can be defined for your case and it will match only implementations of the String SomeInterface.executeSomething(String) method.
  • execution type pointcuts match join points that correspond to when a particular method body is executed
  • call type pointcuts match join points that correspond to when a particular method is called (i.e. the join point is located at the caller side)

执行类型切入点经常使用,但是在某些情况下调用类型切入点也非常有用.

Execution type pointcuts are used more often, but call type pointcuts are very useful too in some cases.

请参见 AspectJ语言/加入点和《 AspectJ编程指南》 中的切入点"一章.

See The AspectJ Language/Join Points and Pointcuts chapter in the AspectJ Programming Guide for further reference.

这篇关于AspectJ-接口实现方法的切入点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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