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

Some examples of common pointcut expressions are given below.java

  • the execution of any public method:spring

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

  • execution(* set*(..))
  • the execution of any method defined by the AccountService interface:this

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

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

  • 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:code

    within(com.xyz.service..*)
  • any join point (method execution only in Spring AOP) where the proxy implements the AccountService interface:orm

    (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 @Classifiedannotation:

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

相關文章
相關標籤/搜索