AOP

1. AOP core concepts

  1. Aspect

  Aspect is a general term for cross business logic.

  2. Joinpoint

  A join point is where an aspect can be woven into the target object (methods, properties, etc.).

  3. Advice

  Notification, which refers to the specific implementation of the aspect.

  4. Pointcut

  Pointcuts refer to the rules that a notification applies to which methods or properties of which classes.

  5. Introduction

  An introduction refers to a special notification that dynamically adds methods or properties to an object.

  6. Weaving

  Weaving refers to inserting a notification into a target object.

  7. Target (target object)

  The target object refers to the object that needs to be woven into the aspect.

  8. Proxy (proxy object)

  The proxy object refers to the object formed after the aspect is woven into the target object.

2. What is AOP (Aspect-oriented programming)

Aspect-Oriented Programming, also known as Aspect-Oriented Programming, or AOP, is a programming technique that allows programmers to modularize behaviors that cross-cut concerns or typical lines of responsibility, such as logging and transaction management. The core construct of AOP is an aspect, which encapsulates behaviors affecting multiple classes into reusable modules.

AOP and IOC are complementary technologies that use a modular approach to solve complex problems in enterprise application development. In a typical object-oriented development approach, logging statements might be implemented in all methods and Java classes to implement logging functionality. In the AOP approach, log services can be modularized in turn and applied declaratively to the required log components. Of course, the advantage is that the Java class does not need to know the existence of the logging service, nor does it need to know the existence of the logging service, nor does it need to consider the related code. So, application code written in Spring AOP is loosely coupled.

The functionality of AOP is fully integrated into the context of Spring transaction management, logging, and various other features.

3. Spring AOP principle

  Spring adopts the JDK dynamic proxy mode to implement the AOP mechanism.

  Spring AOP adopts the process of dynamic proxy:

(1) Dynamically weave the aspect into the target object (the proxied class) using dynamic proxy to form a proxy object;

(2) If the target object does not implement the proxy interface, Spring will use CGLib to generate a proxy object, which is a subclass of the target object;

(3) If the target object is a final class and does not implement the proxy interface, AOP cannot be used.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325386976&siteId=291194637
AOP