spring java.lang.IllegalArgumentException:在切入点 ::0 正式未绑定时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8232339/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 04:45:46  来源:igfitidea点击:

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

springaopspring-aop

提问by rohit

Thinker.java

思想者.java

package springdemo2;

public interface Thinker {
    void thinkOfSomething(String thoughts); 
}

Volunteer.java

志愿者.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

MindReader.java

package springdemo2;

public interface MindReader {
    void interceptThoughts(String thoughts);

    String getThoughts();
}

Magician.java

魔术师.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)

XML(春季)

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

我已包含<aop:aspectj-autoproxy/>在我的 XML 文件中。

I got following Error Message

我收到以下错误消息

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

回答by Jeshurun

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

should be

应该

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

回答by Sllouyssgort

@Before("thinking(thoughts)")

should be

应该

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

回答by zui-coding

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.

Spring 使用 aopalliance.jar:org.aopalliance.intercept.Joinpoint 中的 Joinpoint 接口声明来使用 Annotation 注释。

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

xml配置使用Joinjoint.jar Join语句:org.aspectj.lang.JoinPoint。

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

所以,你应该在方法中使用aspectj的JoinPoint。

回答by user3110162

Whenever java.lang.IllegalArgumentException: error at ::0formal 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.

每当java.lang.IllegalArgumentExceptionerror at ::0在切入点中出现正式未绑定的问题时,请检查您的建议的结构,或者在最大情况下切入点的表达本身就会出现错误。