方法名称以 get 开头的 Spring AOP 切入点 [英] Spring AOP Pointcut with method name starting with get
本文介绍了方法名称以 get 开头的 Spring AOP 切入点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为 Spring AOP 实现切入点.应该记录所有类似于 getXXXX
的方法.我尝试了以下操作,但要么抛出异常,要么不触发:
I'm trying to implement a Pointcut for spring AOP. All the methods which are like getXXXX
should be logged. I tried the following but either they throw exception or does not trigger:
第一次尝试
@Pointcut("within(net.services.*.get*)")
private void clServiceLayer() {}
@Pointcut("within(net.services.*.get*(..))")
private void clServiceLayer() {}
需要关于切入点正确表达的帮助.
Need help with the proper expression for point cut.
推荐答案
within
限制匹配到某些类型内的连接点.相反,您应该使用 execution
Pointcut Designator 来匹配方法执行连接点:
within
limits matching to join points within certain types. Instead you should use execution
Pointcut Designator for matching method execution join points:
@Pointcut("execution(* net.tds.adm.metasolv.customerlink.services.*.get*(..))")
查看 Spring 文档 进行更详细的讨论.
Checkout the Spring Documentation for more detailed discussion.
这篇关于方法名称以 get 开头的 Spring AOP 切入点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文