Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/330.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 adviceexecution()在AspectJ中不起作用_Java_Aspectj - Fatal编程技术网

Java adviceexecution()在AspectJ中不起作用

Java adviceexecution()在AspectJ中不起作用,java,aspectj,Java,Aspectj,我正在学习Java,不知怎的我进入了AspectJ。我试图执行教程中的以下代码: pointcut adviceExecutionPointcut( ) : adviceexecution( ); // Advice declaration before( ) : adviceExecutionPointcut( ) && !within(AdviceExecutionRecipe +) { System.out.println

我正在学习Java,不知怎的我进入了AspectJ。我试图执行教程中的以下代码:

    pointcut adviceExecutionPointcut( ) : adviceexecution( );

   // Advice declaration
   before( ) : adviceExecutionPointcut( )
      && !within(AdviceExecutionRecipe +)
   {
      System.out.println(
         "------------------- Aspect Advice Logic --------------------");
      System.out.println("In the advice picked by ExecutionRecipe");
      System.out.println(
         "Signature: "
            + thisJoinPoint.getStaticPart( ).getSignature( ));
      System.out.println(
         "Source Line: "
            + thisJoinPoint.getStaticPart( ).getSourceLocation( ));
      System.out.println(
         "------------------------------------------------------------");
   }
}
它不知怎么地给了我一个这样的错误

Exception in thread "main" java.lang.StackOverflowError
    at helloWorld.ajc$before$helloWorld$2$5e65e204(helloWorld.aj)
    at helloWorld.ajc$before$helloWorld$2$5e65e204(helloWorld.aj)
    at helloWorld.ajc$before$helloWorld$2$5e65e204(helloWorld.aj)
    at helloWorld.ajc$before$helloWorld$2$5e65e204(helloWorld.aj)
    at helloWorld.ajc$before$helloWorld$2$5e65e204(helloWorld.aj)
作为参考,这是示例代码和建议代码

public class myClass {

    public void foo(int number, String name){
        System.out.println("Inside foo(int, String)");
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
    myClass myObject = new myClass();
    myObject.foo(1, "ican");

    }


public aspect helloWorld {
    public int a;
    long startTime;


    pointcut callPointcut(int value, String name) :
        call(* myClass.foo(int, String)) && args(value,name);

     before(int value, String name) : callPointcut(value,name)
       {
         startTime = System.nanoTime();
          System.out.println("Start Time in ns :" + startTime);
       }

任何帮助都将不胜感激。谢谢

我没有看到包含adviceexecution切入点的方面的类型声明?我怀疑你在你的
helloWorld
方面删除了那个建议块。您得到递归stackoverflow的原因是该建议正在应用于自身。警卫
!在(AdviceExecutionRecipe+
中,用于停止将通知应用于自身。但是,您不能将其从
AdviceExecutionRecipe
更改为
helloWorld
,因为这样它将不适用于您的任何建议。因此,我将把这个advice块放在一个单独的方面,并称之为
adviceecutionrecipe
。有了这一点,它对我很有用:

$ ajc -1.8 *.java -showWeaveInfo

Join point 'adviceexecution(void helloWorld.ajc$before$helloWorld$1$68d3c671(int, java.lang.String))' in Type 'helloWorld' (helloWorld.java:9) advised by before advice from 'AdviceExecutionRecipe' (AdviceExecutionRecipe.java:5)

Join point 'method-call(void myClass.foo(int, java.lang.String))' in Type 'myClass' (myClass.java:10) advised by before advice from 'helloWorld' (helloWorld.java:9)

$ java myClass

------------------- Aspect Advice Logic --------------------
In the advice picked by ExecutionRecipe
Signature: void helloWorld.before(int, String)
Source Line: helloWorld.java:9
------------------------------------------------------------
Start Time in ns :216368803494701
Inside foo(int, String)

我没有看到包含adviceexecution切入点的方面的类型声明?我怀疑你在你的
helloWorld
方面删除了那个建议块。您得到递归stackoverflow的原因是该建议正在应用于自身。警卫
!在(AdviceExecutionRecipe+
中,用于停止将通知应用于自身。但是,您不能将其从
AdviceExecutionRecipe
更改为
helloWorld
,因为这样它将不适用于您的任何建议。因此,我将把这个advice块放在一个单独的方面,并称之为
adviceecutionrecipe
。有了这一点,它对我很有用:

$ ajc -1.8 *.java -showWeaveInfo

Join point 'adviceexecution(void helloWorld.ajc$before$helloWorld$1$68d3c671(int, java.lang.String))' in Type 'helloWorld' (helloWorld.java:9) advised by before advice from 'AdviceExecutionRecipe' (AdviceExecutionRecipe.java:5)

Join point 'method-call(void myClass.foo(int, java.lang.String))' in Type 'myClass' (myClass.java:10) advised by before advice from 'helloWorld' (helloWorld.java:9)

$ java myClass

------------------- Aspect Advice Logic --------------------
In the advice picked by ExecutionRecipe
Signature: void helloWorld.before(int, String)
Source Line: helloWorld.java:9
------------------------------------------------------------
Start Time in ns :216368803494701
Inside foo(int, String)

怎么了?它甚至可以编译吗?在堆栈中粘贴跟踪可能无法编译。它被放在邮局了有什么错?它甚至可以编译吗?在堆栈中粘贴跟踪可能无法编译。已经放在邮局了