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

rohit picture rohit · Nov 22, 2011 · Viewed 32k times · Source

Thinker.java

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(Spring)

I have included <aop:aspectj-autoproxy/> in my XML file.

I got following Error Message

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

Answer

Jeshurun picture Jeshurun · Dec 16, 2011
@Pointcut("execution(* springdemo2."
    + "Thinker.thinkOfSomething(String)) and args(thoughts)")

should be

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