AOP, the core technology in the Spring framework

Table of contents

1. What is AOP?

2. What are the frameworks for implementing AOP technology?

2.1 AOP technology in the Spring framework

2.2 Aspectj Framework

2.3 Summary

3. The way of using AOP in the Aspectj framework

4. Some terminology when using aop in the Aspectj framework

5. Detailed explanation of annotations in AOP

 5.1 @Aspect

 5.2  @Before

 5.3 @AfterReturning

 5.4 @Around

 5.5 @AfterThrowing

 5.6 @After

 5.7 @PointCut


1. What is AOP?

Answer: AOP is aspect-oriented programming, which is Aspect Orient Programming, which is essentially the standardization of dynamic proxy steps.

2. What are the frameworks for implementing AOP technology?

  • Spring Framework
  • Aspectj framework

2.1 AOP technology in the Spring framework

Spring mainly uses AOP in transaction processing, but in actual project development, because the AOP technology implemented by Spring itself is too cumbersome, we rarely use it.

2.2 Aspectj Framework

First of all, Aspectj is a framework dedicated to AOP, so it is more professional and widely used. The Aspectj framework is an open source project of Eclipse.

2.3 Summary

Therefore, when we are developing, although we use the Spring framework, we integrate the AOP technology of the Aspectj framework in the Spring framework, so we remember to add spring-aspectj dependencies to the Spring pom file.

3. The way of using AOP in the Aspectj framework

  • The way of XML configuration file (commonly used in transactions)
  • Annotation method (commonly used)

4. Some terminology when using aop in the Aspectj framework

Aspect: We want to add a new method to the original method. This newly added method is called an aspect. For example, we add log, transaction and other functions to the existing method; at this time, the log method and transaction method are called aspects. .

JoinPot: The join point, which is a method in the target class, is actually the most original method. Whoever adds a new method is the join point.

PoinCut: the entry point, that is, all methods in the target class.

Advice: Also called "notification", "enhancement", (here is the key point, there are 5 annotations in total)

Execution location of the aspect: that is, to enhance those methods in the target class, and the aspect expression will be used here. (emphasis).

5. Detailed explanation of annotations in AOP

5.1 @Aspect

5.2  @Before

 5.3 @AfterReturning

5.4 @Around

5.5 @AfterThrowing

5.6 @After

 5.7 @PointCut

 Summarize:

The above is the core and commonly used content of the AOP technology in the Spring framework. It can be clearly seen that after using AOP, we can standardize the dynamic proxy more standard, but this also requires you to have the most original JDK dynamic proxy. deeper understanding.

Guess you like

Origin blog.csdn.net/weixin_44362089/article/details/127406898