Reputation: 622
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
Upvotes: 12
Views: 36864
Reputation: 1
Caused by: java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut <aop:after-throwing method="except" pointcut-ref="myPointCut" throwing="e"/>
Upvotes: 0
Reputation: 73
Don't use "and" operator to link aspect designators. In Java you can use the "&&" operator. "and" is only available in XML.
Upvotes: 1
Reputation: 166
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.
Upvotes: 0
Reputation: 1
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.
Upvotes: -4
Reputation: 3128
@Before("thinking(thoughts)")
should be
@Before("thinking(String) && args(thoughts)")
Upvotes: 1
Reputation: 23186
@Pointcut("execution(* springdemo2."
+ "Thinker.thinkOfSomething(String)) and args(thoughts)")
should be
@Pointcut("execution(* springdemo2."
+ "Thinker.thinkOfSomething()) && args(thoughts)")
Upvotes: 14