12

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
0

6 Answers 6

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

should be

@Pointcut("execution(* springdemo2."
    + "Thinker.thinkOfSomething()) && args(thoughts)")
Sign up to request clarification or add additional context in comments.

1 Comment

I just can't believe it! the 'and' operator is valid in xml configuration but not in the annotated version. Thanks!
1
@Before("thinking(thoughts)")

should be

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

Comments

1

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

Comments

0

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.

1 Comment

This answer could probably do with some inline formatting or block formatting to make it more readable. Don't forget that case and spelling are important too.
0

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

Comments

-4

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.