【spring源码学习】@Aspect实现切⾯代码的原理
⼀、spring-boot框架中的应⽤
1、服务启动时,会加载spring-boot-autoconfigure的jar中spring.factories⽂件,加载服务启动⾃动装配的类
2、关于动态代理的装配类为
org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.springframework.boot.autoconfigure.aop.AopAutoConfiguration
View Code
3、会导⼊注解@EnableAspectJAutoProxy,导⼊注解后,会引⼊t.annotation.AspectJAutoProxyRegistrar
4、3中的类会向spring容器中注⼊:org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator
⼆、spring容器中bean:AnnotationAwareAspectJAutoProxyCreator
org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator
该类是org.springframework.fig.BeanPostProcessor接⼝的实现,在spring容器创建bean的时候,会调⽤该类的⽅式识别bean是否需要被代理。
遵循spring-aop的规范
advice中隐藏了代理的逻辑
advisor:
org.springframework.aop.aspectj.annotation.InstantiationModelAwarePointcutAdvisorImpl
pointcut:spring aop应用场景
org.springframework.aop.aspectj.AspectJExpressionPointcut
advice:
org.springframework.aop.aspectj.AspectJMethodBeforeAdvice
org.springframework.aop.aspectj.AspectJAroundAdvice
org.springframework.aop.aspectj.AspectJAfterAdvice
org.springframework.aop.aspectj.AspectJAfterThrowingAdvice
org.springframework.aop.aspectj.AspectJAfterReturningAdvice

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。