【问题标题】:error at ::0 formal unbound in pointcut::0 处的错误在切入点中正式未绑定
【发布时间】:2017-03-29 17:20:22
【问题描述】:

项目中的所有类都在 com.aspect 包中。

主要看点:

@Aspect
public class MainAspect {

    @Pointcut("within(com.aspect..*)")
    public void standaloneLayer(){}

}

以帐户对象为参数的连接点的另一个方面:

 @Aspect
    public class AccountAspect {

        @After("com.aspect.MainAspect.standaloneLayer() && args(account)")
        public void pointCutForAccount(JoinPoint joinPoint, Account account){

        }
    }

服务层类:

@Service
public class Customer {
    public void setAccountBalance(Account account) {}
}

在运行应用程序时出现以下异常:

原因:

java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut
  at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:317)

【问题讨论】:

  • 通过在@AfterThrowing 注释中将值属性更改为切入点属性来修复它

标签: java spring-aop


【解决方案1】:

再次交叉检查您的代码是否导入了 org.aopalliance.intercept.Joinpoint 而不是 org.aspectj.lang.JoinPoint 注意 AspectJ AOP 需要导入 org.aspectj.lang.JoinPoint。

【讨论】:

    【解决方案2】:

    就我而言,原因是我导入了错误的类。确保您导入的类是 org.aspectj.lang.JoinPoint 而不是其他任何东西。

    【讨论】:

      【解决方案3】:
      import org.aopalliance.intercept.Joinpoint;
      import org.aspectj.lang.JoinPoint;
      import org.aspectj.lang.annotation.Aspect;
      import org.aspectj.lang.annotation.Before;
      import org.aspectj.lang.annotation.Pointcut;
      
      
      
      
      
      @Aspect
      public class LoggingAspect {
      @Before("allCircleMethods()")
          public void LogginAdvice(JoinPoint joinpoint)
          {
          System.out.println("advice is run");
          System.out.println(joinpoint.toString());
          }
      
      
      @Before("args(String)")
      public void StringArguementMethods()
      {
          System.out.println("A method that takes String arguement has been called");
      }
      
      
      @Pointcut("execution(* get*())")
      public void allgetters()
      {}
      
      @Pointcut("within(as.model.Circle)")
      public void allCircleMethods()
      {}
      
      }
      

      当我导入 import org.aopalliance.intercept.Joinpoint;我在 poincut 错误中得到 0 ubound,所以我将导入更改为 org.aspect.lang.JoinPoint,我的程序运行成功

      【讨论】:

      • 我犯了同样的错误,这可以归因于 IDE 的 Intellisense 建议。人们可能不会密切注意这两个类来自不同的包和名称的大小写差异。我花了 2 个小时才看到这个,谢谢。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多