----------------------------------------------------------------------/n
two distinct types of AOP:
• static AOP : AspectJ’s AOP : the crosscutting logic is applied to your code at compile time,and you cannot change it without modifying the code and recompiling. In static AOP, the weaving process forms another step in the build process for an application.
• dynamic AOP:Spring’s AOP :crosscutting logic is applied dynamically, at runtime. This allows you to make changes
in the distribution of crosscutting without recompiling the application.the weaving process is performed dynamically at runtime.
Spring’s approach is to create proxies for all advised objects,allowing for advice to be invoked as required.
Spring AOP is only a subset of the full AOP feature set found in other implementations like AspectJ.
----------------------------------------------------------------------/n
two different kinds of proxies of Spring AOP
• JDK dynamic proxy
• CGLIB proxy
----------------------------------------------------------------------/n
AOP Concepts:
• Joinpoint: A joinpoint is a well-defined point during the execution of your application. Typical
examples of joinpoints include a call to a method, the method invocation itself, class initialization,
and object instantiation. Joinpoints are a core concept of AOP and define the points
in your application at which you can insert additional logic using AOP.
• Advice: The code that is executed at a particular joinpoint is called the advice. There are many
different types of advice, including before advice, which executes before the joinpoint, and
after advice, which executes after it.
• Pointcuts: A pointcut is a collection of joinpoints that you use to define when advice should
be executed. By creating pointcuts, you gain fine-grained control over how you apply advice
to the components in your application. As mentioned previously, a typical joinpoint is a method
invocation. A typical pointcut is the collection of all method invocations in a particular class.
Often, you can compose pointcuts in complex relationships to further constrain when advice
is executed. We discuss pointcut composition in more detail in the next chapter.
• Aspects: An aspect is the combination of advice and pointcuts. This combination results in
a definition of the logic that should be included in the application and where it should execute.
• Weaving: This is the process of actually inserting aspects into the application code at the
appropriate point. For compile-time AOP solutions, this is, unsurprisingly, done at compile
time, usually as an extra step in the build process. Likewise, for runtime AOP solutions, the
weaving process is executed dynamically at runtime.
• Target: An object whose execution flow is modified by some AOP process is referred to as the
target object. Often, you see the target object referred to as the advised object.
• Introduction: Introduction is the process by which you can modify the structure of an object
by introducing additional methods or fields to it. You can use introduction to make any
object implement a specific interface without needing the object’s class to implement that
interface explicitly.
---------------------------------------------------/n
in Spring AOP at least, is that you can’t advise final classes, because they cannot be overridden and
therefore cannot be proxied.
AOP
最新推荐文章于 2025-08-20 15:04:37 发布