Understanding and using Spring AOP

Spring Framework AOP is thought aspect-oriented programming, using AOP called "cross" technique, the multi-functional business processes involve general extraction and individually packaged to form a separate section, at the right time these facets transverse cut to business processes specified location.

Master AOP implementation technology

  Spring AOP framework of the mechanism that allows developers to common functions in a business process extracted, write function code alone. During the execution of business processes, Spring Framework based business process requirements, the automatic function code written independently of the cutting process to the appropriate location.

AOP programming ideas and terminology

  AOP is an aspect-oriented programming, which programming idea is to spread a different but functionally identical service codes extracted from the business logic, packaged as separate modules, these modules are called independent section, the specific function is called in the method section as concerns. In the course of the business logic implementation, AOP will separate the facets and concerns dynamic cut into business processes, the benefits of doing so is to increase the reusability and maintainability function code.

  Spring framework provides @AspectJ annotation methods and XML-based architecture approach to achieve AOP. In front of the case is XML schema-based method, followed by a method based on @AspectJ will tell annotations. The following combination of previous cases say something about related terms AOP.

  ● Aspect

  A cut face. A separate module to cut business processes. For example, the front case VerifyUser class, an application can have any number of facets.

  ● Join point

  It denotes the point. That is the business process during operation need to insert specific location facets. For example, setTeacher method AopEmailNotice class front case is connected to a point.

  ● Advice

  A notification. It is a section of the concrete implementation. Can be divided into pre-notification (Before), post-notification (AfterReturning), abnormality notification (AfterThrowing), the final notification (the After) and surround notification (Around) are five. Specific implementation are the types notification is specified in the configuration file and annotation. For example, beforeAdvice method VerifyUser class is pre-notification.

  ● Pointcut

  It represents the starting point. Is used to define notifications which should be cut to the point of attachment, different notifications typically requires cutting to different connection points. For example, the front case profiles <aop: pointcut> tag.

  ● Target

  It represents the target object. One or more objects to be notified section. For example, the front case AopEmailNotice class.

  ● Proxy

  It represents the proxy object. After the object is dynamically created tells the application to the target object. As can be easily understood, the business logic for the proxy object function of the target object to be cut is cut together with the object formed.

  ● Weaving

  Cut express, also known as weaving. The cut to the target object is to create a new proxy object of the process. This process can occur at compile time, the class loader and Operating Periods.

summary

(1) This program explores the idea of ​​AOP, the main idea is to allow developers to common functions of many business processes extracted, write a separate function code to form independent modules, which are also known as section. During the execution of business processes, Spring Framework based business process requirements, automatically cut to the appropriate position of cutting processes.

Implementation (2) AOP specific implementation steps: First, to write separate modules need to cut the business process (also referred to as section) and the starting point (Method module); and disposed AOP Spring configuration file, add the cut surface , the starting point and the need to cut the target Bean; and finally write test code.

 

reference:

1、https://baijiahao.baidu.com/s?id=1613310315603029991&wfr=spider&for=pc

2, https://www.jianshu.com/p/a21256903fdd (examples easier to understand, spring boot example)

3、https://blog.csdn.net/q982151756/article/details/80513340

4、https://blog.csdn.net/fygu18/article/details/79989862

5、https://my.oschina.net/guangshan/blog/1797461

 

Guess you like

Origin www.cnblogs.com/116970u/p/11441784.html