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*())
我需要知道上面的切入点表达式为什么错误?
注意:该错误是在执行主类后出现的,但是主类没有任何问题,而是在切入点表达式内出现该错误
不正确的切入点表达式。
从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问题