12
votes

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
6

6 Answers

14
votes
@Pointcut("execution(* springdemo2."
    + "Thinker.thinkOfSomething(String)) and args(thoughts)")

should be

@Pointcut("execution(* springdemo2."
    + "Thinker.thinkOfSomething()) && args(thoughts)")
1
votes
@Before("thinking(thoughts)")

should be

@Before("thinking(String) && args(thoughts)")
1
votes

Don't use "and" operator to link aspect designators. In Java you can use the "&&" operator. "and" is only available in XML.

0
votes

However, if the parameters of each method are not the same, how to do?

I'll tell you:

Spring uses the Annotation annotation using the Joinpoint interface declaration in aopalliance.jar:org.aopalliance.intercept.Joinpoint.

The xml configuration is used Joinjoint.jar Join statement:org.aspectj.lang.JoinPoint.

So, you should use aspectj's JoinPoint in method.

0
votes

Caused by: java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut <aop:after-throwing method="except" pointcut-ref="myPointCut" throwing="e"/>

-4
votes

Whenever java.lang.IllegalArgumentException : error at ::0 formal unbound in pointcut like problem occur then kindly check the structure of your advice, or expression of pointcut in maximum cases error will be there itself.