【问题标题】:Spring AOP Pointcut with method name starting with get方法名称以 get 开头的 Spring AOP 切入点
【发布时间】:2016-05-25 22:09:31
【问题描述】:

我正在尝试为 Spring AOP 实现一个切入点。应该记录所有类似于getXXXX 的方法。我尝试了以下方法,但它们要么抛出异常,要么不触发:

第一次尝试

@Pointcut("within(net.services.*.get*)")
private void clServiceLayer() {}

@Pointcut("within(net.services.*.get*(..))")
private void clServiceLayer() {}

在切入点的正确表达方面需要帮助。

【问题讨论】:

  • 为什么是within?你可以使用@Pointcut("execution(* net.tds.adm.metasolv.customerlink.services.*.get*(..))")
  • 您的建议已经奏效。谢谢你。如果您将其放在答案中,我会将其标记为已回答。

标签: java spring aop spring-aop


【解决方案1】:

within 将匹配限制为特定类型内的连接点。相反,您应该使用execution Pointcut Designator 来匹配方法执行连接点:

@Pointcut("execution(* net.tds.adm.metasolv.customerlink.services.*.get*(..))")

查看Spring Documentation 了解更详细的讨论。

【讨论】:

    猜你喜欢
    • 2020-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多