spring AOP 常用表达式

58 篇文章 0 订阅

Some examples of common pointcut expressions are given below.

  • 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)

     

    'this' is more commonly used in a binding form :- see the following section on advice for how to make the proxy object available in the advice body.

     

  • any join point (method execution only in Spring AOP) where the target object implements the AccountService interface:

    target(com.xyz.service.AccountService)

     

    'target' is more commonly used in a binding form :- see the following section on advice for how to make the target object available in the advice body.

     

  • any join point (method execution only in Spring AOP) which takes a single parameter, and where the argument passed at runtime is Serializable:

    args(java.io.Serializable)

    'args' is more commonly used in a binding form :- see the following section on advice for how to make the method arguments available in the advice body.

    Note that the pointcut given in this example is different to execution(* *(java.io.Serializable)): the args version matches if the argument passed at runtime is Serializable, the execution version matches if the method signature declares a single parameter of type Serializable.

  • any join point (method execution only in Spring AOP) where the target object has an @Transactional annotation:

    @target(org.springframework.transaction.annotation.Transactional)

     

    '@target' can also be used in a binding form :- see the following section on advice for how to make the annotation object available in the advice body.

     

  • any join point (method execution only in Spring AOP) where the declared type of the target object has an @Transactional annotation:

    @within(org.springframework.transaction.annotation.Transactional)

     

    '@within' can also be used in a binding form :- see the following section on advice for how to make the annotation object available in the advice body.

     

  • any join point (method execution only in Spring AOP) where the executing method has an @Transactional annotation:

    @annotation(org.springframework.transaction.annotation.Transactional)

     

    '@annotation' can also be used in a binding form :- see the following section on advice for how to make the annotation object available in the advice body.

     

  • any join point (method execution only in Spring AOP) which takes a single parameter, and where the runtime type of the argument passed has the @Classified annotation:

    @args(com.xyz.security.Classified)

     

    '@args' can also be used in a binding form :- see the following section on advice for how to make the annotation object(s) available in the advice body.

     

  • any join point (method execution only in Spring AOP) on a Spring bean named 'tradeService':

    bean(tradeService)
  • any join point (method execution only in Spring AOP) on Spring beans having names that match the wildcard expression '*Service':

    bean(*Service)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值