Spring Review (iii) AOP

Source: Internet
Author: User

1. What is AOP and its benefits * Aspect Oriented Programming Aspect-Oriented Programming.

AOP focuses on joint processing and can be applied to multiple target objects in a certain rule through configuration. The advantage is to reuse components, improve program structure, and improve flexibility. Decouples non-target objects of common components.

2. AOP related concepts *

1) Aspect (Aspect) refers to the common service processing, which can be used multiple times by multiple target objects.
2) The JoinPoint connection point refers to the position where the plane component works on the target object. For example, an exception occurs when the method is used.
3) The Pointcut entry point is a set of connection points, which are specified using expressions.
4) Target Object
5) Advice notification refers to the pipeline executed by the plane component at the connection point. For example, before a method call, after a method call, or before or after a method call.
6) After the AutoProxy scheme proxy adopts the AOP scheme, the object returned by the container is the proxy object. During use, the proxy object calls the functions of the cut plane component and the target object.
A. the target object has interfaces using JDK proxy,
B. No interface for the target object uses CGLIB proxy

Aspect> used to configure the aspect
Consumer id attribute
The Correlated ref attribute is used to associate the bean of the slice.
Used to set the entry point
The regular expression attribute is similar to a regular expression)
Execution () is used to set method limits
Execution (* tarena. service .*.*(..))
Indicates that the return type is not limited, and the specified tarena. service package is limited
All methods, parameter types are not limited
Before is used for the pointcut and method.

3. Notification Type **

1) pre-notification

Run the command before the target method calls callback. Can Stop subsequent execution, unless an exception is thrown
2) Post-Notification

Run the command after the target method calls callback. The target method is executed only when it ends normally.
3) final notification

Run the command after the target method calls callback. If the target method is normal, all exceptions are executed.
4) exception notification

Run the command after an exception occurs in the target method call.
5) surround notification

Run the command before and after the target method is called.

These five types of notifications are organized in this way during internal calls.
Try {
Call pre-notification
Surround Processing
Call the method of the target object
Surround Post Processing
Post-Call Notification
} Catch (Exception e ){
Call exception notification
} Finally {
Call final notification
}


Note:

1. note that a post-pass notification will be prompted when the program is executed normally. If the target method encounters an exception, no post-notification will be executed (post-notification is called after the execution of the target method is successful. If the execution of the target method fails (an exception occurs), the post-notification will not be called)

2. The final notification will be executed no matter whether an exception occurs or not.


4. AOP annotation configuration ** 1) enable AoP annotation configuration in xml configuration
Bytes
2) use the Aop annotation in the aspect component
Reply @ Aspect
Success @ Pointcut

Outputs @ Before, @ After, @ AfterReturing, @ AfterThrowing, @ Around



You are welcome to join us in the discussion and study!

Collect it by yourself!

Record and share, let you grow together! Welcome to my other blog; my blog address: http://blog.csdn.net/caicongyang


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.