Exception:java.lang.IllegalArgumentException:切入点格式不正确?

问题描述 投票:0回答:1
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个回答
3
投票

不正确的切入点表达式。

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问题

© www.soinside.com 2019 - 2024. All rights reserved.