Common notation for spring pointcut expressions

Source: Internet
Author: User

Spring AOP users may often use execution pointcut indicators. The execution expression is in the following format:

Execution (Modifiers-pattern? Ret-type-pattern Declaring-type-pattern? Name-pattern (Param-pattern)          Throws-pattern?)

All parts are optional except the return type pattern (Ret-type-pattern in the code snippet above), the name pattern, and the parameter pattern. The return type mode determines that the return type of the method must match one connection point in turn. The most frequent return type pattern you will use is * that it represents a match for any return type. A fully qualified type name will only match the method that returns the given type. The name pattern matches the method name. You can use * wildcards as all or part of a naming pattern. The parameter pattern is slightly more complex: () matches a method that does not accept any parameters, and (..) matches a method that accepts any number of parameters (0 or more). The pattern (*) matches a method that accepts a parameter of any type. The pattern (*,String) matches a method that accepts two parameters, the first of which can be any type, and the second must be of type string. For more information, see the Language Semantics section of the ASPECTJ Programming Guide.

Some examples of common pointcut expressions are given below.

  • Execution of any public method:

    Execution (Public * * (.. ))
  • The execution of a method whose name begins with "set":

    Execution (* set* (.. ))
  • AccountServiceExecution of any method defined by the interface:

    Execution (* com.xyz.service.accountservice.* (.. ))
  • Execution of any method defined in the service package:

    Execution (* com.xyz.service.*.* (.. ))
  • Execution of any method defined in a service package or its child packages:

    Execution (* com.xyz.service). *.*(.. ))
  • Any connection point in the service package (only method execution in spring AOP):

    Within (com.xyz.service.*)
  • Any connection point in the service package or its child package (only method execution in spring AOP):

    Within (Com.xyz.service. *)
  • AccountServiceany connection point that implements the proxy object for the interface (only method execution in spring AOP):

    This (Com.xyz.service.AccountService)

    ' This ' is more commonly used in binding forms:-See the following notification section for information on how to make a proxy object available in the notification body.

  • AccountServiceany connection point that implements the target object of the interface (only method execution in spring AOP):

    Target (Com.xyz.service.AccountService)

    ' Target ' is more commonly used in binding forms:-See the following notification section for information on how to make a target object available in the notification body.

  • Either one takes only one parameter, and the arguments passed in at run time are the Serializable connection points of the interface (only method execution in spring AOP)

    Args (java.io.Serializable)

    ' args ' is more commonly used in binding forms:-See the following notification section for information on how to make method parameters available in the notification body.

    Note that the pointcut given in the example differs from the execution(* *(java.io.Serializable)) following: The args version only matches when the incoming parameter is serializable at dynamic runtime, whereas the execution version declares only one type of parameter in the method signature Serializable .

  • Any connection point in the target object that has an @Transactional annotation (only method execution in spring AOP)

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

    ' @target ' is more commonly used in binding forms:-See the following notification section for information on how to make a callout object available in the notification body.

  • The type of any target object declaration has a @Transactional connection point for annotations (only method execution in spring AOP):

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

    ' @within ' is more commonly used in binding forms:-See the following notification section for information on how to make a callout object available in the notification body.

  • Any one executed method has an @Transactional annotated connection point (only method execution in spring AOP)

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

    ' @annotation ' is more commonly used in binding forms:-See the following notification section for information on how to make a callout object available in the notification body.

  • Any one that accepts only one parameter, and the parameter type passed in by the runtime has an @Classified annotated connection point (only method execution in spring AOP)

    @args (com.xyz.security.Classified)

    ' @args ' is more commonly used in binding forms:-See the following notification section for information on how to make a callout object available in the notification body.

  • Any tradeService connection point above the spring bean named ' ' (only method execution in spring AOP):

    Bean (TradeService)
  • Any connection point above the spring bean whose name matches the wildcard expression " *Service (only method execution in spring AOP):

    Bean (*service)

Common notation for spring pointcut expressions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.