Translation official website SPRINGAOP (1)

Source: Internet
Author: User
Tags aop connection pooling websphere application server


Original English from Spring Framework Reference 4.0
http://docs.spring.io/spring/docs/4.0.0.BUILD-SNAPSHOT/spring-framework-reference/htmlsingle/#aop

This article provides a convention for:
* After each text, attach my translation
* Translation does not translate verbatim, so adding additional text makes the translation content easier for Chinese readers to understand.
* There is no authoritative translation of AOP terminology in China, so when you talk about AOP, it is recommended that you use some terms and nouns directly in English.



Aspect oriented Programming with Spring
Using spring's aspect-oriented programming (AOP represents Aspect oriented programming= aspect-oriented programming)


Introductionspring 2.0 AOP
Introduction to Spring 2.0 AOP



Aspect-oriented Programming (AOP) complements object-oriented programming (OOP) by providing another way of thinking about Program structure. The key unit of modularity in OOP is the class, whereas in AOP the "modularity is" the aspect. Aspects enable the modularization of concerns such as transaction management that cut across multiple types and objects. (Such concerns are often termed crosscutting concerns in AOP literature.)

AOP complements object-oriented programming (OOP represents object-oriented programming= object-oriented programming), and AOP provides methods that are different from OOP to think about how to organize the structure of a program. In OOP, the main composition of a program is class, whereas in AOP it is the aspect (aspect) that is specifically described after aspect details. Aspect enables the idea of some program functionality to form modules, such as the idea of a transaction management (transaction management) to form a module, since transaction management is often used by several classes-and it is necessary to make transaction management an independent modularity. (The idea of such forming modules is often called crosscutting ideas in AOP), crosscutting ideas =crosscutting concerns. (in OOP, a subclass can only be erected below to enjoy the parent-class function above.) AOP lets a class without a parent-child relationship, which is a parallel class, can use some of the same functionality.



One of the key components of Spring is the AOP framework. While the Spring IoC container does isn't depend on AOP, meaning you don't need to use AOP if you don t want to, AOP comple ments Spring IoC to provide a very capable middleware solution.

In the spring framework, AOP is a critical part. But spring's IOC does not need AOP support, which means you can not use AOP if you just use the spring IOC. It is noteworthy that AOP enables the spring IoC to provide a very powerful middleware solution.

Spring 2.0 introduces a simpler and more powerful way of writing custom aspects using either a schema-based approach or th e @AspectJ annotation style. Both of these styles offer fully typed advice and use of the AspectJ Pointcut language, while still using Spring AOP for W Eaving.

The Spring 2.0 Schema-and @AspectJ-based AOP support is discussed in this chapter. Spring 2.0 AOP remains fully backwards compatible with Spring 1.2 AOP, and the Lower-level AOP support offered by the SPRI NG 1.2 APIs are discussed in the following chapter.
(These two paragraphs do not need to be read, because the terminology has not yet been explained.) Pro, please be patient, in the back there is an explanation. The terminology does not understand, is not understood. )


The AOP is used in the Spring Framework to ...
Use AOP to ...

... provide declarative enterprise services, especially as a replacement for EJB declarative services. The most important such service is declarative transaction management.
。。。 Provide declarative Enterprise Services (declarative Enterprise Services use server-side capabilities that are invoked without writing Java programs, and are configured with text or like WebSphere Application server to improve Web pages to configure the required server features)
。 In particular, AOP is able to replace the declarative services of EJBS (EJB provides Java Objects on remote hosts to be used and these Java Objects, performance and a wide variety of configuration issues, basically eliminated). The most important of these is declarative transaction management.

Allow users to implement custom aspects, complementing their use of OOP with AOP.
Allow developers to implement homemade aspect, which can be implemented with complementary OOP design capabilities.

Warning:if you are interested to generic declarative services or other pre-packaged declarative services such as pooling, you don't need to work directly with Spring AOP, and can skip most the This chapter.

Note: If you are only concerned with common declarative services or declarative services for preconfigured middleware, such as pooling services (database connection pooling), you do not have to use spring AOP.


AOP Concepts
AOP Concepts and Definitions
Let us begin by defining some the concepts and terminology. These terms are are not spring-specific ... Unfortunately, AOP terminology is not particularly intuitive; However, it would be even the more confusing if Spring used its own terminology.
Let's first define some important AOP concepts and terminology. These terms are not set by spring authors (AOP terminology is defined by some pioneer computer scientists). And these terms are not very intuitive. So if the spring author defines these terms, these terms may be more difficult to understand.

aspect:a Modularization of a concern that cuts across multiple. Transaction Management is a good the example of a crosscutting concern in enterprise Java applications. In Spring AOP, aspects are implemented using regular classes (theschema-based approach) or regular classes with The @Aspect annotation (the @AspectJ style). Slice (Aspect): The idea of a modular program that allows a function or service to traverse through several classes without a parent-child relationship. (That is, a parallel class uses the same feature). Transaction management is a good example of this cross-cutting idea. In spring AOP, Aspect is implemented by developers using a generic Java Class or Java Annotation (@Aspect).
join Point:a Point during the execution of a, such as the execution of a or the handling of a except Ion. In Spring AOP, a join point always represents a method execution.
· Execution point: A point in time that can be used during the execution of a program method or during an exception-handling time. Spring AOP Join point can only be performed in the execution of program methods. (In spring AOP, Join Point is a point in time during the execution of a Java method, such as a point in time: When executing the 1th line of code in a Java method).
The translator's words: The term join point translated into ' execution time ' is my literal translation, suggesting that you directly use the English Join point as a term for communication with others. The following terminology is also a direct use of English pronunciation to communicate better.
Advice:action taken by a aspect in a particular join point. Different types of advice include "around," "before" and "after" advice. (Advice types are discussed below.) Many AOP frameworks, including Spring, model an advice as aninterceptor, maintaining a chain of interceptors around the JO In point.
Recommendations and Requirements (Advice): Refers to a join point point-in-time, an action or function is aspect use. There are several types of advice: 1.around,before, after. (similar to the call-back approach to the life-cycle management of the bean, the bean's lifecycle is largely managed by the Spring IoC container). Most AOP frameworks, including Spring AOP, assemble a advice into a kick-intercepter (Interceptor), so before or after a join point Point-in-time or later, AOP The framework maintains and manages a set of strings of interceptors.


POINTCUT:A predicate that matches join points. Advice is associated with a pointcut expression and runs in any join point matched by the pointcut (for example, the EXECU tion of a method with a certain name. The concept of join points as matched by pointcut expressions is-to-AOP, and Spring uses the AspectJ pointcut expr Ession language by default.
Tangent point (Pointcut): A pre-configured time range that can overwrite one and more join points points. A advice that is configured with Pointcut, if one of the join point is right within the point cut range, the advice will run, which means that the intercepter will run. Join point can be covered by point cut, which is an AOP and core concept. By default, configuring Pointcut in Spring uses the AspectJ pointcut expession Language.

introduction:declaring Additional methods or fields on behalf of a type. Spring AOP allows to introduce the new interfaces (and a corresponding implementation) to any advised object. For example, your could use a introduction to make a bean implement anismodified interface, to simplify caching. (An introduction is known as a inter-type declaration in the AspectJ community.)
Introduction (Introduction): refers to the addition of methods or fields.
Target Object:object being advised by one or more aspects. Also referred to as Theadvised object. Since Spring AOP is implemented using runtime proxies, this object would always be aproxied object.
Target object: Is the object that is configured to advice. In Sping AOP, Target object is always represented in the runtime of the program, specifically this object will not be invoked directly by the developer's program, which is invoked directly by the AOP proxy object, which is generated by spring.
AOP Proxy:an object created by the "AOP framework in" to implement the aspect contracts (advise method executions And so on). In the Spring Framework, an AOP proxy would be a JDK dynamic proxy or a cglib proxy.
The AOP PROXY:AOP proxy object, which is generated by spring, is to complete the aspect conventions, such as advise execution. In the spring framework, the AOP proxy object uses JDK dynamic proxy or Cglib proxy. (These two proxy is the byte code generator)


weaving:linking aspects with the other application types or objects to create a advised object. This can is done in compile time (using the AspectJ compiler, for example), load time, or at runtime. Spring AOP, like the pure Java AOP frameworks, performs weaving at runtime.
Connection (weaving): Aspect and objects are connected to form objects with advise. Completion of the connection (weaving) can be time,run time in compile time,load. Spring AOP is a runtime complete connection (weaving).







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.