An overview of the "Step-by-step learning Spring" AOP

Source: Internet
Author: User
Tags ming

1. What is AOP

In the software industry, AOP is the abbreviation for Aspect oriented programming, which means: face-cutting programming, through the pre-compilation method and runtime dynamic agent to implement the unified maintenance of the program functions of a technology.

    • AOP takes a horizontal extraction mechanism to address repetitive code for public functions (performance monitoring, transaction management, security checks, caching)

Spring AOP uses a pure Java implementation that does not require specialized compilation procedures and class loading to weave the enhanced code into the target class at run time by proxy.

2. Why AOP

Give me a chestnut:

Requirement 1: to add the authentication feature to a save feature.

Traditional Development mode: Add authentication methods to the relevant classes, add calls to the method in the function.

Requirement 2: the customer is satisfied with this authentication function, which is required to add this function to all the module's save functions involved.

Traditional development model: It would be foolish to repeat the authentication method in a specific implementation class again like the above. Then the method is extracted into a base class, and the related methods inherit the base class, so that the method can be reused.

introduction of AOP: using a horizontal extraction mechanism instead of vertical inheritance. essentially, this horizontal extraction is a proxy operation. Extracting an authentication proxy class, adding the authentication operation to the related function in the proxy class, without modifying the original business class.

3. AOP-related terminology
    • Joinpoint (connection point): A point that can be intercepted. In spring, these points refer to methods because only connection points of the method type are supported in spring.
    • Pointcut (pointcut): The point that is really intercepted.
    • Advice (Notification/enhancement): What to do after interception. such as the Checkprivilege method in the example above.
      • Pre-Notification: Execute before method execution
      • Post-Notification: Executes after the method executes, regardless of whether the exception was successfully executed or thrown
      • Final notification: Execution after successful execution of the method, exception or error not performed
      • Exception notification: Method throws an exception before execution, and does not execute on success
      • Surround notification: Includes the above four annotations
    • Target: The target object being enhanced.
    • Weaving (Weaving): the process of adding enhanced skills to a target object to create a new proxy object. such as Xiao Ming and will sing the process of Xiao Ming.
      • Spring uses dynamic proxy weaving, while the ASPECTJ is woven into the compile-time and class-loading stages.
    • Proxy: When a class is augmented by AOP, it produces a result proxy class.
    • Aspect (tangent): a combination of pointcuts and notifications.

An overview of the "Step-by-step learning Spring" AOP

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.