【问题标题】:Why this syntax error in SpringAOP @pointcut not popping any Error?为什么 Spring AOP @pointcut 中的这个语法错误没有弹出任何错误?
【发布时间】:2018-11-20 16:54:01
【问题描述】:

我正在学习 SpringAOP,在运行基本程序时,我观察到 eclipse(当然是编译器)的奇怪行为。

当我在 @Pointcut 注释上练习时,我错误地在 Pointcut 表达式中添加了另一个括号。令人惊讶的是,我在运行时没有收到任何错误。加上它的作用就像魅力一样。它甚至不关心我在最后添加了多少个圆括号..如果我更改该表达式中的任何其他语法它会弹出一个错误..

这里是语法错误..

 @Pointcut("execution(* com.kish.DAO.*.*(..))))))") 
    public void forPointcut() {}

我为@Before Advices 使用了切入点表达式引用。

@Before("forPointcut()")
public void beforeAddAccountant() {
    System.out.println(" \n----->>>>>  exceuting @Before advice before adding accountant");
}


@Before("forPointcut()")
public void otherLoggers() {
    System.out.println("----->>>>> execution @Pointcut references before methods\n");

}

谁能告诉我这里发生了什么?

【问题讨论】:

  • @GhostCat 你太棒了..谢谢。

标签: java spring annotations spring-aop pointcut


【解决方案1】:

是的,我可以。 AspectJ 切入点解析器在这里很宽松,就这么简单。这是因为它应该被 AspectJ 编译器使用,并且我们有更彻底的检查产生语法错误。但是,当被 Spring AOP 使用时,解析后没有进一步的检查,因为没有生成字节码。结果是第一个多余的右括号之后的所有内容都被转储了,例如

execution(* *(..)))))) && !target(java.lang.String)

变成

execution(* *(..))

在 Spring AOP 中。

请尽量坚持正确的语法。

【讨论】:

    猜你喜欢
    • 2015-01-11
    • 1970-01-01
    • 1970-01-01
    • 2018-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-15
    • 2016-03-22
    相关资源
    最近更新 更多