Spring AOP brief summary

(This article is a summary of editors collected in the study notes, only to learn, if infringement, please contact me)

( AOP core concepts move from Bowen Address: http://www.cnblogs.com/xrq730/p/4919025.html )

 

 

The AOP (Aspect Oriented Programming)


AOP (Aspect Oriented Programming), that is, aspect-oriented programming, can be said to OOP (Object Oriented Programming, Object Oriented Programming) added and improved. OOP introduced as encapsulation, inheritance, polymorphism, etc. concept to build a hierarchy of objects, used to simulate the behavior of a common set. However, OOP allows developers to define vertical relationship, but are not suitable for transverse relationship defined, for example, the log function. Log code tends to spread laterally in all object hierarchy, the core object corresponding to the function it no relation to other types of code, such as security, exception handling, and continuity are also transparent so, this spread independent code is referred to throughout the transverse (cross cutting), in OOP design, which led to a lot of code repetition, to the detriment of reusable modules.

Contrary AOP technology, which uses a technique called "transverse", the internal cross-sectional decapsulates the object, and those that affect the behavior of the public classes encapsulated into a plurality of reusable modules, and named it " Aspect ", namely section. The so-called "cut", it simply is that nothing to do with business, but it is the responsibility of the business logic or common module called encapsulated, easy to duplicate code to reduce system and reduce the degree of coupling between modules, and facilitate future operability and maintainability.

Use "cross-cutting" technology, AOP the software system is divided into two parts: the core concerns and crosscutting concerns. The main flow of business processes is a core concern, not part of the relationship is with crosscutting concerns. Features a crosscutting concern is that they often occur in many core concerns, and everywhere essentially similar, such as certification authority, log things. AOP is that the various concerns separation system, the core and crosscutting concerns separated.


Pre-notification, the notification final rear, rear return notification, abnormality notification rear surround notifications


AOP core concepts

1, crosscutting concerns

Intercept of which methods, how to deal with the interception, these concerns called crosscutting concerns

2, section (Aspect)

Class is an abstract object features, is the abstract section of crosscutting concerns

3, the connection point (JoinPoint)

Is intercepted point, because only the supporting method Spring type connection point, the point of attachment in Spring method is to be intercepted, in fact, the point of attachment may also be field or constructors

4, entry point (the pointcut)

Define the connection point of interception

5, the notification (advice)

After the code is called the notification means refers to the connection point of interception to be performed, a notification is divided into front, rear, abnormal end, surrounded by five notifications

6, the target object

Acting audience

7, weaving (Weave)

The cut to the target object and the process leading to the proxy object created

8, is introduced (Introduction)

Under the premise of not modifying code, the introduction of some methods or fields may be added to the class dynamically at runtime


 

AOP programming is actually very simple thing, look at AOP programming, the programmer need only participate in three parts:

1, the definition of common business components

2, the definition of a starting point, a starting point may cross a plurality of business components

3, the definition enhancement processing, enhancement processing in the operation processing is the frame AOP component is woven into ordinary traffic

So the key is to define the entry points and the definition AOP enhancement processing program, once the entry point and define an appropriate enhancement processing, AOP AOP proxy frame is automatically generated, namely: proxy object processing method is a method = + enhancement proxy object.


II: Method Description section

@Aspect

Role of the current class is identified as a read section for container

@Before

A pre-identification method for enhancing function corresponding to BeforeAdvice

@AfterReturning

Rear enhanced, equivalent to AfterReturningAdvice, executed when the method exits

@AfterThrowing

Enhanced exception is thrown, the equivalent of ThrowsAdvice

@After

final enhancement, whether it is throwing an exception or normal exit will be executed

@Around

Surround enhancement corresponds MethodInterceptor


@Pointcut("execution(public * com.example.controller.*.*(..))")  

 

execution point cut function

execution function for executing a connection point matching method, the syntax is:

execution (Method modifier (optional) method returns the type of the abnormal pattern parameter name (optional)) 

-------------------------------

Wildcards parameter section:

* Matches any character, but only one element matching

.. matches any character can match any of a plurality of elements and representing the class, and must be used in conjunction *

+ Must be followed after the class name, such as the Horseman +, it represents the class itself and all classes inherit or extend the specified class

Released five original articles · won praise 3 · Views 352

Guess you like

Origin blog.csdn.net/Young_IT/article/details/82798144
Recommended