【问题标题】:java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcutjava.lang.IllegalArgumentException: ::0 处的错误在切入点中正式未绑定
【发布时间】:2011-11-22 19:07:07
【问题描述】:

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(弹簧)

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

我收到以下错误消息

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

【问题讨论】:

    标签: spring aop spring-aop


    【解决方案1】:
    @Pointcut("execution(* springdemo2."
        + "Thinker.thinkOfSomething(String)) and args(thoughts)")
    

    应该是

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

    【讨论】:

    • 我简直不敢相信! 'and' 运算符在 xml 配置中有效,但在带注释的版本中无效。谢谢!
    【解决方案2】:
    @Before("thinking(thoughts)")
    

    应该是

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

    【讨论】:

      【解决方案3】:

      不要使用“and”运算符来链接方面指示符。在 Java 中,您可以使用“&&”运算符。 "and" 仅在 XML 中可用。

      【讨论】:

        【解决方案4】:

        但是,如果每个方法的参数不一样,怎么办?

        我会告诉你:

        Spring通过aopalliance.jar:org.aopalliance.intercept.Joinpoint中的Joinpoint接口声明使用Annotation注解。

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

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

        【讨论】:

        • 这个答案可能与一些inline formatting 或块格式有关,以使其更具可读性。不要忘记大小写和拼写也很重要。
        【解决方案5】:

        原因:java.lang.IllegalArgumentException: ::0 切入点中的正式未绑定错误 throwing="e"/>

        【讨论】:

          【解决方案6】:

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-06-14
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多