码迷,mamicode.com
首页 > 编程语言 > 详细

Spring AOP中pointcut expression表达式解析

时间:2016-09-20 18:09:14      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:

注解@Pointcut 是指哪些方法 需要被执行 AOP,是由“PointCut Expression”

Pointcut 可以有下列方式来定义或者 通过 && || 和 ! 方式进行组合

@args()

@execution()

@target()

@within()

@annotation()

 

其中 execution 是用的最多的,其格式为:

execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern) throws-pattern?)

ret-type-pattern:可以为*表示任何返回值,全路径的类名等.

declaring-type-pattern 

name-pattern:指定方法名,*代表所以,set*,代表以set开头的所有方法.

parameters pattern:指定方法参数(声明的类型),(..)代表所有参数,(*)代表一个参数,(*,String)代表第一个参数为任何值,第二个为String类型.

 

execution(修饰类型 返回类型 )

modifiers-pattern 修饰类型(可选):可取值, public ,protected,private,* (* 代表全部)

ret-type-pattern 返回类型 :可取值, 所有可以作为返回类型的名字,自定义类可以写包的路径(用正则表达式匹配)

declaring-type-pattern

举例说明:(问:到底哪里需要空格呢?空格加多了有影响吗?)

任意公共方法的执行:

  execution(public * *(..))

任何一个以“set” 开始的方法的执行

  execution(* set*(..))

AccountService 接口的任意方法的执行

  execution(* com.xyz.service.AccountService.*(..)))

定义在service 包里的任意方法的执行

  execution(* com.xyz.service.*.*(..))

定义在service 包和所有子包里的任意类的任意方法的执行

  execution(* com.xyz.service..*.*(..))

Spring AOP中pointcut expression表达式解析

标签:

原文地址:http://www.cnblogs.com/panie2015/p/5889729.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!