Spring 2.x framework Learning (serialization)-learn about AOP

Source: Internet
Author: User

Preface:

This article will provide a deep understanding and learning through serialization.SpringRelated core technologies and implementation principles. IncludingSpringOfBeanLifecycle management, declarative transaction management,AOPManagement, annotation application implementation, andRelated Applications that are extended on it.

This article introducesSpring AOP.

Let's take a lookAOPRelated Concepts:

1)Aspect (Section): Indicates that the abstract of a cross-cutting concern is a cut. Similar to the class, the focus of the two is different. The class is the abstraction of Object Features, while the aspect is the abstraction of cross-cutting concerns.

2)Joinpoint (Connection Point): Points intercepted. InSpringThese points refer to methods, becauseSpringOnly connection points of the method type are supported. In fact, the connection points can also beFieldOr class constructor.

3)Advice (Notification): Refers to the things to be done after interception to the connection point. They are divided into pre-notification, post-notification, exception notification, final notification, and surround notification.

4)Pointcut (Entry Point): Refers toJointpointDefinition of interception.

5)Target (Target object): The target object to be implemented by the proxy.

6)Weave (Woven): RefersAspectsApplyTargetObject and causeProxyObject creation process.

7)Introduction (Introduction): Without modifying the class code,IntroductionYou can dynamically add some methods or attributes for the class during runtime.

SpringOfAOPPowerful configuration functions, such as automatic proxy(Autoproxy), ProvideXMLAnd annotation configuration method. No matter which configuration is supported, its final nature is throughJdkDynamicAopProxyOrCglibProxyFactoryCompleted objectAOPSupports interception.

One of the following configuration methods is used:(Based onBeanName auto-Proxy Support)To explainSpring AOPImplementation Principle:

The following is a configuration example::


BeanNameAutoProxyCreatorString or wildcardBeanAutomatic CreationAOPProxy.

Below isBeanNameAutoProxyCreatorClass graph, which implementsBeanPostProcessorInterface.


Introduction in the previous chapterSpring BeanIntroduction to Lifecycle ManagementBeanPostProcessorYesSpringInBeanBefore and after the object is instantiated, the corresponding method is called back.

SoBeanNameAutoProxyCreatorIs IMPLEMENTEDPostProcessBeforeInstantiationMethodBeanBefore the object is implementedAOP.

The core code is as follows::


In the code, it will callCreateProxyMethod To implement automatic code encapsulation of object instances.

Analyze the code: CreateProxyThe method is actually called.SpringOfProxyFactoryProxy encapsulation implementation for objects

The main implementation code is marked below:


NextAopProxyFactoryYesSpringProvided interface class,SpringDefaultDefaultAopProxyFactoryImplementation class.

Let's analyze it again.CreateAopProxyMethod implementation,The main implementation Code marked below


Note: We found the above CodeSpringForBeanObjectAOPTwo methods are used for processing. If there is an interface classJDKDynamicAopProxyIf it is a common class, useCglibProxyFacotry. AboutCglibFor details about this project, refer to the instructions on its official website.

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.