Spring Aop配置時的切入點表達式


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)

對應的中文:

任意公共方法的執行:
execution(public * *(..))
任何一個以“set”開始的方法的執行:
execution(* set*(..))
AccountService 接口的任意方法的執行:
execution(* com.xyz.service.AccountService.*(..))
定義在service包里的任意方法的執行:
execution(* com.xyz.service.*.*(..))
定義在service包或者子包里的任意方法的執行:
execution(* com.xyz.service..*.*(..))
在service包里的任意連接點(在Spring AOP中只是方法執行) :
within(com.xyz.service.*)
在service包或者子包里的任意連接點(在Spring AOP中只是方法執行) :
within(com.xyz.service..*)
實現了 AccountService 接口的代理對象的任意連接點(在Spring AOP中只是方法執行) :
this(com.xyz.service.AccountService)
'this'在binding form中用的更多:- 請常見以下討論通知的章節中關於如何使得代理對象可以在通知體內訪問到的部分。
實現了 AccountService 接口的目標對象的任意連接點(在Spring AOP中只是方法執行) :
target(com.xyz.service.AccountService)
'target'在binding form中用的更多:- 請常見以下討論通知的章節中關於如何使得目標對象可以在通知體內訪問到的部分。
任何一個只接受一個參數,且在運行時傳入的參數實現了 Serializable 接口的連接點 (在Spring AOP中只是方法執行)
args(java.io.Serializable)
'args'在binding form中用的更多:- 請常見以下討論通知的章節中關於如何使得方法參數可以在通知體內訪問到的部分。 請注意在例子中給出的切入點不同於 execution(* *(java.io.Serializable)): args只有在動態運行時候傳入參數是可序列化的(Serializable)才匹配,而execution 在傳入參數的簽名聲明的類型實現了 Serializable 接口時候匹配。
有一個 @Transactional 注解的目標對象中的任意連接點(在Spring AOP中只是方法執行)
@target(org.springframework.transaction.annotation.Transactional)
'@target' 也可以在binding form中使用:請常見以下討論通知的章節中關於如何使得annotation對象可以在通知體內訪問到的部分。
任何一個目標對象聲明的類型有一個 @Transactional 注解的連接點(在Spring AOP中只是方法執行)
@within(org.springframework.transaction.annotation.Transactional)
'@within'也可以在binding form中使用:- 請常見以下討論通知的章節中關於如何使得annotation對象可以在通知體內訪問到的部分。
任何一個執行的方法有一個 @Transactional annotation的連接點(在Spring AOP中只是方法執行)
@annotation(org.springframework.transaction.annotation.Transactional)
'@annotation' 也可以在binding form中使用:- 請常見以下討論通知的章節中關於如何使得annotation對象可以在通知體內訪問到的部分。
任何一個接受一個參數,並且傳入的參數在運行時的類型實現了 @Classified annotation的連接點(在Spring AOP中只是方法執行)
@args(com.xyz.security.Classified)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM