java.lang.IllegalArgumentException:切入点处于:: 0正式未绑定时出错

roh*_*hit 10 aop spring spring-aop

Thinker.java

package springdemo2;

public interface Thinker {
    void thinkOfSomething(String thoughts); 
}
Run Code Online (Sandbox Code Playgroud)

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;
    }
}
Run Code Online (Sandbox Code Playgroud)

MindReader.java

package springdemo2;

public interface MindReader {
    void interceptThoughts(String thoughts);

    String getThoughts();
}
Run Code Online (Sandbox Code Playgroud)

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;
    }
}
Run Code Online (Sandbox Code Playgroud)

XML(春季)

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

我收到了以下错误消息

 java.lang.IllegalArgumentException: error at ::0 formal unbound in
 pointcut
Run Code Online (Sandbox Code Playgroud)

Jes*_*run 13

@Pointcut("execution(* springdemo2."
    + "Thinker.thinkOfSomething(String)) and args(thoughts)")
Run Code Online (Sandbox Code Playgroud)

应该

@Pointcut("execution(* springdemo2."
    + "Thinker.thinkOfSomething()) && args(thoughts)")
Run Code Online (Sandbox Code Playgroud)

  • 我简直不敢相信!'and'运算符在xml配置中有效,但在带注释的版本中无效.谢谢! (3认同)