【问题标题】:Exception: java.lang.IllegalArgumentException: Pointcut is not well-formed Error?异常:java.lang.IllegalArgumentException:切入点不是格式正确的错误?
【发布时间】:2020-01-11 15:35:18
【问题描述】:
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class MyDemoLogginAspect {

    @Before("execution(* * add*())")
    public void beforeAddAccountAdvice(){

        System.out.println("Executing before");

    }
}

我得到了一个例外原因:

 java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting '(' at character position 14
execution(* * add*()) 

我想知道为什么上面的切入点表达式是错误的?

注意:这个错误是在主类执行后出现的,但主类没有问题,错误是在切入点表达式中

【问题讨论】:

    标签: java spring aop pointcut


    【解决方案1】:

    切入点表达式不正确。

    来自documentation

    执行表达式的格式为:

    execution(modifiers-pattern? ret-type-pattern 
    declaring-type-pattern?name-pattern(param-pattern)throws-pattern?)
    

    您的示例工作的正确格式是

    @Before("execution(* add*())")
    

    修饰符模式是可选的,不能是通配符 (*),应该是 public 或 protected 之一。详情here

    所以切入点表达式也可能是

    @Before("execution(public * add*())")
    

    另请注意,您的切入点表达式过于全局,可能会导致不希望的结果,正如 kriegaex 在此 answer 中指出的另一个 SO 问题

    【讨论】:

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