Introduction to Spring Use (vi)--AOP detailed

Source: Internet
Author: User
Tags deprecated

First, the pointcut syntax

1) wildcard characters

Wildcard characters supported by AOP:

*: matches any number of characters

.. : matches any number of characters, matches any number of sub-packages in type mode, matches any number of parameters in the method parameter pattern

+: Matches subtypes of the specified type and can be placed only as suffixes behind type mode

Instance:

java.lang.String    Match String type java.*. String     matches the string type under any "one-level sub-package" Under the Java package, such as matching java.lang.String, but matching java.string or java.lang.ss.Stringjava: *       Match any type of Java package and any sub-packages, such as Java. String, java.lang.Stringjava.lang.*ing      matches the type ending with ing in any Java.lang package java.lang.number+   Matches any Java.lang.Number subtype, such as Java.lang.Integer, Java.math.BigInteger

2) type match, syntax as follows:

Annotations? The fully qualified name of the class

    • annotations: Optional, annotations held on type
    • fully qualified name of class: required, any class fully qualified name

3) method matching, syntax is as follows:

Annotations?  Modifier? return value type type declaration? Method name (parameter list) exception list?

    • annotations: Optional, Notes held on the method
    • modifiers: optional, such as public, protected
    • return value type: required, can be any type mode, "*" means all types
    • type declaration: optional, can be any type mode
    • method Name: required, "*" denotes any method name
    • parameter list: required, such as:
      • () means that the method does not have any parameters
      • (..) Represents a method that accepts any parameter
      • (.., java.lang.String) means that the method accepts the end of a parameter of type java.lang.String and can accept any argument in front of it
      • (*,java.lang.string) means that the method accepts the end of an argument of type java.lang.String and accepts an arbitrary type argument in front of it
    • exception list: optional, with "throws exception fully qualified Name list" declaration, the exception fully qualified name list if there are multiple "," split, such as throws Cn.matt.exception1,cn.matt.exception2

4) pointcut Expression logical operator

AOP is used and (&&), or (| | ), Non-(! ) to combine pointcut expressions

In XML, "&&" must use the escape character "&&" Instead, it is inconvenient, so spring provides and, or, not to replace the &&, | |,!

Note: The alternates (and, or, not) are only available in XML and are parsed incorrectly when used in annotation mode

5) The execution command executes using the "Execution (method expression)" matching method

Instance:

Public * * (..)    Execution of any public method * Cn.javass. *.*(..)    Cn.javass any method of any class under package and all sub-packages * Cn.javass. ipointcutservice.* (*)    Cn.javass Package and all sub-packages under the Ipointcutservice interface have only one parameter method * Cn.javass: ipointcutservice+.* ()    Cn.javass Package and any non-parametric method of Ipointcutservice interface and subtype under all sub-packages * (Cn.javass. ipointcutservice+&& java.io.serializable+). * (..)    Any method that implements the type of Ipointcutservice interface and java.io.Serializable interface under the Cn.javass package and all sub-packages is @java. lang.deprecated @cn. Javass. Secure  * * (..)    Any holding @java.lang.deprecated and @cn.javass. The secure annotation method    holds @cn.javass for any type of method defined: Secure method

Two

Introduction to Spring Use (vi)--AOP detailed

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.