Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 317
rohit Avatar asked Nov 22 '11 19:11

rohit


People also ask

What method does this Pointcut expression reference?

In Spring AOP, a join point always represents a method execution. A pointcut is a predicate that matches the join points, and the pointcut expression language is a way of describing pointcuts programmatically.

What does spring offers fully typed advice mean?

Spring offers fully typed advice - meaning that you declare the parameters you need in the advice signature (as we saw for the returning and throwing examples above) rather than work with Object[] arrays all the time.

How does AOP work in spring boot?

AOP (Aspect-Oriented Programming) is a programming pattern that increases modularity by allowing the separation of the cross-cutting concern. These cross-cutting concerns are different from the main business logic. We can add additional behavior to existing code without modification of the code itself.

Which annotations are used to declare advice in Spring AOP?

We can use @Before annotation to mark an advice type as Before advice. After (finally) Advice: An advice that gets executed after the join point method finishes executing, whether normally or by throwing an exception. We can create after advice using @After annotation.


3 Answers

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

should be

@Pointcut("execution(* springdemo2."
    + "Thinker.thinkOfSomething()) && args(thoughts)")
like image 111
Jeshurun Avatar answered Sep 29 '22 01:09

Jeshurun


@Before("thinking(thoughts)")

should be

@Before("thinking(String) && args(thoughts)")
like image 31
Enginer Avatar answered Sep 29 '22 02:09

Enginer


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

like image 35
Ioan Simiciuc Avatar answered Sep 29 '22 02:09

Ioan Simiciuc