Example of Spring AOP Definition

Source: Internet
Author: User

Spring AOP users may frequently useExecutionPointcut designator. The execution expression format is as follows:

 
Execution (modifiers-pattern? Ret-type-pattern declaring-type-pattern? Name-pattern (param-pattern) throws-pattern ?)

Besides the return type mode (CodeRet-type-pattern in the Part). All parts except the name mode and parameter mode are optional. The return type mode determines that the return type of the method must match a connection point in sequence. The most frequently used return type mode is*It indicates matching any return type. Only the methods of the given type are returned. The name pattern matches the method name. You can use*Wildcard characters are used as all or part of naming rules. The parameter mode is a bit complicated:()Matches a method that does not accept any parameters, while(..)Matches a method that accepts any number of parameters (zero or more ). Mode(*)Matches a method that accepts any type of parameter. Mode(*, String)Matches a method that accepts two parameters. The first method can be of any type, and the second method must be of the string type. See the language semantics section in the aspectj programming guide.

Below are some examples of common entry point expressions.

  • Execution of any public method:

    Execution (Public **(..))
  • Execution of any method starting with "set:

    Execution (* Set *(..))
  • AccountserviceExecution of any method of the interface:

    Execution (* COM. XYZ. Service. accountservice .*(..))
  • Define the execution of any method in the service package:

    Execution (* COM. XYZ. Service .*.*(..))
  • Define the execution of any method in the service package or sub-package:

    Execution (* COM. XYZ. Service ..*.*(..))
  • Any connection points in the service package (only method execution in Spring AOP ):

    Within (COM. XYZ. Service .*)
  • Any connection points in the service package or sub-package (only method execution in Spring AOP ):

    Within (COM. XYZ. Service ..*)
  • ImplementedAccountserviceAny connection point of the proxy object of the interface (only method execution in Spring AOP ):

    This (COM. XYZ. Service. accountservice)

    'It' is used in binding form more:-see the section on how to enable proxy objects to be accessed in the notification body in the following sections.

  • ImplementedAccountserviceAny connection point of the target object of the interface (only method execution in Spring AOP ):

    Target (COM. XYZ. Service. accountservice)

    'Target' is used in binding form:-see the following section on how to make the target object accessible in the notification body.

  • Each parameter accepts only one parameter and is passed in at runtime.SerializableInterface connection point (only method execution in Spring AOP)

    ARGs (Java. Io. serializable)

    'Args 'is used in binding form:-see the following section for details about how to make method parameters accessible in the notification body.

    Note that the starting point in the example is different fromExecution (** (Java. Io. serializable )): ARGs matches the input parameter serializable only during dynamic running, while execution implements the signature declaration type of the input parameter.SerializableInterface.

  • There is@ TransactionalArbitrary connection points in the annotation target object (in Spring AOP, only method execution is performed)

    @ Target (Org. springframework. transaction. annotation. Transactional)

    '@ Target' can also be used in binding form: see the section in the notice section about how to make annotation objects accessible in the notification body below.

  • The declared type of any target object has one@ TransactionalAnnotation connection point (only method execution in Spring AOP)

    @ Within (Org. springframework. transaction. annotation. Transactional)

    '@ Within' can also be used in binding form:-see the following sections for details about how to enable annotation objects to be accessed in the notification body.

  • Any method for execution has one@ TransactionalAnnotation connection point (only method execution in Spring AOP)

    @ Annotation (Org. springframework. transaction. annotation. Transactional)

    '@ Annotation' can also be used in binding form:-see the following sections for details about how to enable an annotation object to be accessed in the notification body.

  • Any one accepts a parameter, in addition, the input parameter type implements the connection point of @ classified annotation (in Spring AOP, only method execution is performed)

     @ ARGs (COM. XYZ. security. classified) 

    '@ ARGs' can also be used in binding form: -The following section describes how to enable an annotation object to be accessed in the notification body.

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.