2011-11-22 81 views
10

Thinker.javajava.lang.IllegalArgumentException异常:在错误:: 0正式绑定在切入点

package springdemo2; 

public interface Thinker { 
    void thinkOfSomething(String thoughts); 
} 

Volunteer.java

package springdemo2; 

public class Volunteer implements Thinker{ 
    private String thoughts; 

    @Override 
    public void thinkOfSomething(String thoughts) { 
     this.thoughts=thoughts; 
    } 

    public String getThoughts(){ 
     return thoughts; 
    } 
} 

MindReader.java

package springdemo2; 

public interface MindReader { 
    void interceptThoughts(String thoughts); 

    String getThoughts(); 
} 

Magician.java

package springdemo2; 

import org.aspectj.lang.annotation.Aspect; 
import org.aspectj.lang.annotation.Before; 
import org.aspectj.lang.annotation.Pointcut; 

@Aspect 
public class Magician implements MindReader { 

    private String thoughts; 

    @Pointcut("execution(* springdemo2." 
      + "Thinker.thinkOfSomething(String)) and args(thoughts)") 
    public void thinking(String thoughts){ 
    } 

    @Override 
    @Before("thinking(thoughts)") 
    public void interceptThoughts(String thoughts) { 
     this.thoughts=thoughts; 
     System.out.println("Advice method intercepted Thoughts..."+thoughts); 
    } 

    @Override 
    public String getThoughts() { 
     return thoughts; 
    } 
} 

XML(春季)

我已经包含在我的XML文件<aop:aspectj-autoproxy/>

我得到了以下错误消息

java.lang.IllegalArgumentException: error at ::0 formal unbound in 
pointcut 

回答

11
​​

应该

@Pointcut("execution(* springdemo2." 
    + "Thinker.thinkOfSomething()) && args(thoughts)") 
+3

我简直不敢相信! '和'运算符在xml配置中有效,但不在注释版本中。谢谢! –

1
@Before("thinking(thoughts)") 

应该

@Before("thinking(String) && args(thoughts)") 
-3

w ^每当java.lang.IllegalArgumentExceptionerror at ::0正式解锁在切入点像问题发生然后善意地检查您的建议的结构,或在最大的情况下,切入点的表达错误将在那里本身。 ?

0

但是,如果每个方法的参数是不一样的,怎么办

我会告诉你:

Spring使用使用aopalliance.jar的连接点接口声明的注解注释: org.aopalliance.intercept.Joinpoint。

使用xml配置Joinjoint.jar加入语句:org.aspectj.lang.JoinPoint。

所以,你应该在方法中使用aspectj的JoinPoint。

+1

这个答案可能可以通过一些'行内格式化'或块格式化来提高可读性。不要忘记,案例和拼写也很重要。 – halfer

相关问题