AOP——AOP表达式

方法签名匹配:

expression(<method scope> <return type> <fully qualified class name>.*(parametes))
  • method scope: Advice will be applied to all the methods having this
    scope. For e.g., public, private, etc. Please note that Spring AOP
    only supports advising public methods.

  • return type: Advice will be applied to all the methods having this
    return type.

  • fully qualified class name: Advice will be applied to all the methods
    of this type. If the class and advice are in the same package then
    package name is not required

  • parameters: You can also filter the method names based on the types.
    Two dots(..) means any number and type of parameters.

示例:
execution(* com.aspects.pointcut.DemoClass.*(..)) 匹配DemoClass下所有的方法。
execution(public com.aspects.pointcut.DemoClass.*(int,int)) 匹配DemoClass下public、参数为两个int的方法。

类型签名匹配:

适用于类型符合的多有joinpoint

within(type name)  

“type name”可以使包名称也可以是类名称

示例:
within(com.aspects.blog.package.*) : 匹配 com.aspects.blog.package包下所有类的所有方法。(注意:com.aspects.blog.package.abc下的类方法并不匹配)

within(com.aspects.blog.package..*) 匹配 com.aspects.blog.package包下所有类的所有方法,并且匹配其子包下所有类的所有方法。

within(com.aspects.blog.package.DemoClass) 匹配com.aspects.blog.package.DemoClass下所有方法

within(com.aspects.blog.package.DemoInterface+) : 匹配这个接口的所有实现类的所有方法

AOP表达式逻辑计算

Pointcut expressions can be combined using && (and), ||(or), and !(not).

within(com.aspects.blog.package.DemoInterface+)|| within(com.aspects.blog.package.DemoInterface2+)

匹配DemoInterface或者DemoInterface2的实现类中的所有方法

更多示例:

//the execution of any public method:
execution(public * *(..))

//the execution of any method with a name beginning with "set":
execution(* set*(..))

//the execution of any method defined by the AccountService interface:
execution(* com.xyz.service.AccountService.*(..))

//the execution of any method defined in the service package:
execution(* com.xyz.service.*.*(..))

//the execution of any method defined in the service package or a sub-package:
execution(* com.xyz.service..*.*(..))

//any join point (method execution only in Spring AOP) within the service package:
within(com.xyz.service.*)

//any join point (method execution only in Spring AOP) within the service package or a sub-package:
within(com.xyz.service..*)

//any join point (method execution only in Spring AOP) where the proxy implements the //AccountService interface:
this(com.xyz.service.AccountService)

http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值