Spring AOP easy to understand summary of the principles

What is aop: traditional oop development on the code logic in this process will produce a number of cross-cutting issues that our main business logic has little to do, it will be scattered in various parts of the code, making it difficult to maintain, aop idea is to put the business logic and cross-cutting issues of separation, to achieve the purpose of decoupling, diamante improve reusability and development efficiency;
application scenarios:
logging, rights verification, transaction management, thread pool closed, etc.

aop kind of dynamic proxy to use?
when bean is the interface or subclass proxy present implementation, --- jdk dynamic proxy;
no interface exists, spring will be used to generate a proxy object CGLIB;

Source analysis:
(. 1): @ EnableAspectJAutoProxy to the container (beanFactory) in a register AnnotationAwareAspectJAutoProxyCreator objects;
(2): AnnotationAwareAspectJAutoProxyCreator is a post-processor, after initialization of the target object using the notification mechanism BeanPostProcessor rear complete AOP objects to the target object to create, inside the object, and is packaged JDK two CGlib technical, dynamically created proxy object;
(3): the target method performs proxy object, mesh obtained Interceptor chain standard methods using blocker chain mechanism, change into each interceptor execution

Guess you like

Origin www.cnblogs.com/liuyang-93/p/12617220.html