SPRING IN ACTION 第4版笔记-第四章ASPECT-ORIENTED SPRING-002-AOP术语解析

一、

1.Advice

Advice是切面的要做的操作,它定义了what、when(什么时候要做什么事)

aspects have a purpose—a job they’re meant to do. In AOP terms, the job
of an aspect is called advice.
Advice defines both the what and the when of an aspect. In addition to describing
the job that an aspect will perform, advice addresses the question of when to perform

the job. Should it be applied before a method is invoked? After the method is
invoked? Both before and after method invocation? Or should it be applied only if a
method throws an exception?
Spring aspects can work with five kinds of advice:
 Before—The advice functionality takes place before the advised method is
invoked.
 After—The advice functionality takes place after the advised method completes,
regardless of the outcome.
 After-returning—The advice functionality takes place after the advised method
successfully completes.
 After-throwing—The advice functionality takes place after the advised method
throws an exception.
 Around—The advice wraps the advised method, providing some functionality
before and after the advised method is invoked.

2.JOIN POINTS

一个应用程序可以有无数的点可以织入aspect,这些点就是连接点。一个连接点是描述当应用程序执行什么操作时要织入aspect。这个时机可以一个方法的被调用、抛出异常,甚至是一个类的成员变量被修改时。

The join points are all the points within the execution flow of the application that are candidates to have advice applied.

3.POINTCUTS

大多数情况下,并非所有连接点都需要aop,Pointcut就是用来缩小需要aop的连接点范围。如果说一个advice描述了切面的what和when问题,那么Pointcut就是描述了切面的where问题。pointcut definition matches one or more join points at which advice should be woven。通常Pointcut用类名及方法名或表达式来定义。

The pointcut defines where (at what join points) that advice is applied. The key concept you should take from this is that pointcuts define which join points get advised.

4.Aspect

aspect是advice和pointcut的组合。

An aspect is the merger of advice and pointcuts. Taken together, advice and pointcuts define everything there is to know about an aspect—what it does and where and when it does it.

5.INTRODUCTIONS

An introduction allows you to add new methods or attributes to existing classes.比如在一个类中增加一个维护状态值的功能

6.Weaving

Weaving is the process of applying aspects to a target object to create a new proxied object. The aspects are woven into the target object at the specified join points. The weaving can take place at several points in the target object’s lifetime:
 Compile time—Aspects are woven in when the target class is compiled. This
requires a special compiler. AspectJ’s weaving compiler weaves aspects this way.
 Class load time—Aspects are woven in when the target class is loaded into the
JVM . This requires a special ClassLoader that enhances the target class’s byte-
code before the class is introduced into the application. AspectJ 5’s load-time
weaving ( LTW ) support weaves aspects this way.
 Runtime—Aspects are woven in sometime during the execution of the applica-
tion. Typically, an AOP container dynamically generates a proxy object that del-
egates to the target object while weaving in the aspects. This is how Spring AOP aspects are woven.

原文地址:https://www.cnblogs.com/shamgod/p/5238463.html