2011-11-22 83 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

相關問題