AOP 术语 — 摘自 《spring in action》

"Before you walk the walk, you have to learn to talk the talk"


An aspect is the cross-cutting functionality you are implementing. It is the aspect,

or area, of your application you are modularizing. The most common (albeit sim-

ple) example of an aspect is logging. Logging is something that is required

throughout an application. However, because applications tend to be broken

down into layers based on functionality, reusing a logging module through inher-

itance does not make sense. However, you can create a logging aspect and apply it

throughout your application using AOP.


A joinpoint is a point in the execution of the application where an aspect can be

plugged in. This point could be a method being called, an exception being

thrown, or even a field being modified. These are the points where your aspect’s

code can be inserted into the normal flow of your application to add new behavior.


Advice is the actual implementation of our aspect. It is advising your application

of new behavior. In our logging example, the logging advice would contain the

code that implements the actual logging, such as writing to a log file. Advice is

inserted into our application at joinpoints.


A pointcut defines at what joinpoints advice should be applied. Advice can be

applied at any joinpoint supported by the AOP framework. Of course, you don’t

want to apply all of your aspects at all of the possible joinpoints. Pointcuts allow

you to specify where you want your advice to be applied. Often you specify these

pointcuts using explicit class and method names or through regular expressions

that define matching class and method name patterns. Some AOP frameworks

allow you to create dynamic pointcuts that determine whether to apply advice

based on runtime decisions, such as the value of method parameters.


An introduction allows you to add new methods or attributes to existing classes

(kind of mind-blowing, huh?). For example, you could create an Auditable advice

class that keeps the state of when an object was last modified. This could be as

simple as having one method, setLastModified(Date), and an instance variable

to hold this state. This can then be introduced to existing classes without having to

change them, giving them new behavior and state.


A target is the class that is being advised. This can be either a class you write or a

third-party class to which you want to add custom behavior. Without AOP, this

class would have to contain its primary logic plus the logic for any cross-cutting

concerns. With AOP, the target class is free to focus on its primary concern, obliv-

ious to any advice being applied.


A proxy is the object created after applying advice to the target object. As far as

the client objects are concerned, the target object (pre-AOP) and the proxy object

(post-AOP) are the same—as it should be. That is, the rest of your application will

not have to change to support the proxy class.


Weaving is the process of applying aspects to a target object to create a new, prox-

ied object. The aspects are woven into the target object at the specified joinpoints.


Interceptor  在 Joinpoint  被执行时进行一下拦截,然后执行一系列Advice。比如 一个serviceInterceptor可以拦截所有service方法,然后执行 Transaction Advice 和 Logging Advice


Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.