Spring AOP and Spring AOP

Source: Internet
Author: User

Spring AOP and Spring AOP

As the core part of Spring, AOP plays an important role in Spring. AOP divides the software system into two parts: core focus and cross-cutting focus. The main process of business processing is the core focus, and the part that has little to do with it is the cross-cutting focus. One feature of cross-cutting concerns is that they often occur in multiple places of core concerns, and are similar everywhere. For example, permission authentication, logs, and transaction processing. The function of Aop is to separate the various concerns in the system from the core concerns and the cross-cutting concerns.

The technology for Implementing AOP is mainly divided into two categories: one is to use dynamic proxy technology, and use the method of intercepting messages to describe the message to replace the execution of the original object behavior; the second is to use static weaving to introduce specific syntax to create "aspect", so that the compiler can weave "aspect" code during compilation.

About dynamic proxy and static proxy principle, you can refer to: http://www.cnblogs.com/yfyzy/p/4401833.html

Before learning about Spring AOP, let's take a look at the terminology related to AOP.

1. Notification (Advice)
The notification defines what the aspect is and when to use it. Describes the work to be done and when to execute this job, just like the time and place we usually say during the appointment.
2. Join point (Joinpoint ):
The program can apply a "time" of the notification, which is the connection point, such as when the method is called or an exception is thrown.
3. Pointcut)
The notification defines the "story" and the time when the "story" takes place. The starting point defines the location where the "story" takes place, such as the name of a class or method, spring allows us to easily use regular expressions to specify
4. Aspect)
The notification and the entry point form the intersection: time, location, and "story" to happen"
5. Introduction (Introduction)
Introduction allows us to add new methods and attributes to existing classes (Spring provides a method injection function)
6. Target)
That is, the notification object. If no AOP is available, its logic will be divided into other transaction logic, with AOP, it can focus only on what you want to do (AOP allows him to do what he wants to do with sex)
7. proxy)
The object of the Application Notification. For details, see the proxy mode in the design mode.
8. Weaving)
The process of applying a cut surface to a target object to create a new proxy object is usually as follows:
(1) Compile time: When a class file is compiled, it is woven into a special compiler. For example, AspectJ can be woven into the compiler.
(2) class loading: use special ClassLoader to enhance the byte code of the class before the target class is loaded to the program.
(3) runtime: the plane is woven into the plane at a certain time during runtime. SpringAOP is woven into the plane in this way. The principle should be that the dynamic proxy technology of JDK is used.

Use Cases of AOP

AOP is used to encapsulate cross-cutting concerns. It can be used in the following scenarios:

Authentication permission

Caching Cache

Context passing content transmission

Error handling

Lazy loading

Debugging

Logging, tracing, profiling and monitoring record tracking optimization Calibration

Performance optimization

Persistence

Resource pooling Resource pool

Synchronization

Transactions transaction

Spring our common proxy implementation methods are sound and annotated.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.