Annotation Method
1. Define the Aspect using Aspect
2. Define PointCut and Advice in Aspect
3. Enable AspectJ's support for Annotation and configure the Aspect class and target object to the IOC container.
Define a class, indicating that @ Aspect defines a method labeled as Pointcut ("execution (* add * (..)") to define the sequence of method execution before ("pointcutname ").
The final generation is a proxy.
AOP:
Cross-cutting concerns: Cross cutting concern
Aspect: Aspect
Specific Method to be implanted: Advice
Entry Point: Pointcut
Joinpoint
Implant: Weave
Target Object: target Object
Proxy: Proxy
Dynamic Method: Introduction
Configuration file method:
<Aop: config>
<Aop: aspect id = "security" ref = "securityHandler">
<Aop: pointcut id = "alladdmethod" expression = "execution (* cn. synjones. dreams. usermanagerimpl. add * (...)"/>
<Aop: before method = "checkSecurity"/>
</Aop: aspect>
</Aop: config>
By default, Aspect does not need to implement interfaces. However, for the target object, interfaces must be implemented by default. If the interface is not implemented, the CGLIB library must be introduced.
If the target object implements the interface, the dynamic proxy of JDK is used by default to implement AOP. You can also use the CGLIB library to implement AOP.
If the target object does not implement an interface, the CGLIB library must be used. Spring will automatically convert between the JDK dynamic proxy and CGLIB.
Differences between JDK dynamic proxy and CGLIB bytecode generation:
1. JDK dynamic proxy can only generate a proxy for the class that implements the interface, rather than the class.
2. CGLIB is the proxy for class implementation. It mainly generates a subclass for the specified class and overwrites the method. Because it is integrated, it is best not to declare the method as final.
How to force the use of CGLIB to implement AOP?
1. Introduce the CGLIB library,/cglib/*. jar
<Aop: aspectj-autoproxy proxy-target-class = "true"/>
Joinpoint
You can use the joinpoint parameter in Advice to obtain the parameter of the execution method: joinpint. getArgs ();