Application scenarios of AOP

Use of spring AOP

  1. Affairs
  2. Log processing
  3. Cache
  4. Access control
  5. Error handling
  6. Lazy loading

What is AOP

AOP (Aspect Orientend Programing) is called: aspect-oriented programming, it is a kind of programming idea. When the program is running, the code is dynamically cut into the specified method of the class. The programming idea at the specified position is that the aspect-oriented programming is
based on the agent idea. For the original target object, the original business method is enhanced without modifying the original object code

What is a pointcut in Spring AOP

Before talking about the entry point, you need to talk about the connection point.
Connection point: the point that may be enhanced, all the methods in the target class.
Entry point: the connection point that will be enhanced, the method that is enhanced in the target class

What is the target object in Spring AOP

Target class: the class that needs to be enhanced

AOP and proxy mode

Proxy mode: divided into static proxy, JDK dynamic proxy, cglib proxy

  1. Today, the proxy
    class and the proxy class implement a common interface (or inheritance). There are references to the proxy class in the proxy class. When the proxy class is actually executed, the method of the proxy class is actually executed.
  2. jdk dynamic proxy: There must be an interface and an implementation class (target class), and the proxy class corresponding to the interface is produced by the tool Proxy, thereby enhancing the target class.
  3. Cglib proxy: The proxy class generated by the cglib proxy is a subclass of the target class, and all target classes cannot be modified with final

AOP
SpringAOP enhances the target class by proxy.
The bottom layer of SpringAOP uses JDK dynamic proxy by default, which can be modified to cglib proxy through configuration

How do you understand the concepts of Joinpoint, Pointcut, Advice, Introduction, Weaving, and Aspect in AOP?

1. Target class (target): The class that needs to be enhanced.
2. Connection point (Joinpoint): the point that may be enhanced, all methods in the target class.
3. Pointcut: The connection point that will be enhanced, the method that is enhanced in the target class.
4. Notification/Enhancement (Advice): The content enhanced for the entry point. Enhanced content is usually embodied in the form of methods. The location of enhanced execution is different, and the name is different.
(Pre-notification, post-notification, surrounding notification, exception notification, final notification)
The class where the notification method is located is usually called the aspect class.
5. Aspect: The combination of notification and entry point. One notification corresponds to one entry point to form a line, multiple notifications correspond to multiple entry points to form multiple lines, and multiple lines form a surface, which we call a cut surface.
6. Weaving: The process of generating aspects and creating proxy objects. (The process of combining notifications and entry points, and creating proxy objects)
7. Introduction: a special enhancement

Guess you like

Origin blog.csdn.net/weixin_43464372/article/details/108277056