Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java AspectJ-接口方法的切入点';实施_Java_Aspectj - Fatal编程技术网

Java AspectJ-接口方法的切入点';实施

Java AspectJ-接口方法的切入点';实施,java,aspectj,Java,Aspectj,我有几个SomeInterface的实现。问题是在SomeInterface的所有实现中,方法executeSomething的切入点是什么 public class SomeImplementation implements SomeInterface { public String executeSomething(String parameter) { // Do something } } public class AnotherImplementa

我有几个SomeInterface的实现。问题是在SomeInterface的所有实现中,方法executeSomething的切入点是什么

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
    }

}

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

execution(public String SomeInterface+.executeSomething(String))
call(public String SomeInterface+.executeSomething(String))
关于这些切入点类型的一些解释:

  • 这两个切入点中使用的类型模式意味着:返回
    String
    的所有公共方法,这些方法在
    SomeInterface
    或其任何子类型中定义,命名为
    executeMething
    并接受单个
    String
    参数。这是可以为您的案例定义的最具体的类型模式,它将只匹配
    String SomeInterface.executemething(String)
    方法的实现
  • 执行类型切入点匹配执行特定方法体时对应的连接点
  • 调用类型切入点匹配调用特定方法时对应的连接点(即连接点位于调用方端)
执行类型的切入点使用得更多,但在某些情况下,调用类型的切入点也非常有用


更多参考请参见中的章节。

您真的对接口的所有实现都感兴趣吗,“所有类都有名为X的方法”就足够了吗?如果是这样,您可以使用
@Pointcut(“execution(**.executesmething(..)”)
,对吗?如果没有其他类(不是接口的实现),则“所有具有名称为X的方法的类”都可以。谢谢你的建议,但理想情况下我需要所有的实现