zoukankan      html  css  js  c++  java
  • 【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,导入注解后,会引入org.springframework.context.annotation.AspectJAutoProxyRegistrar

    4、3中的类会向spring容器中注入:org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator

    二、spring容器中bean:AnnotationAwareAspectJAutoProxyCreator

    org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator

    该类是org.springframework.beans.factory.config.BeanPostProcessor接口的实现,在spring容器创建bean的时候,会调用该类的方式识别bean是否需要被代理。

    遵循spring-aop的规范

    advice中隐藏了代理的逻辑

    advisor:

    org.springframework.aop.aspectj.annotation.InstantiationModelAwarePointcutAdvisorImpl

    pointcut:

    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

  • 相关阅读:
    如何在Ubuntu 20.04 LTS Focal Fossa上安装Webmin
    如何在Linux服务器上创建一个具有管理权限的新用户?
    如何在Ubuntu 20.04 LTS上安装Apache Subversion
    error more than one devices and emulator
    深度学习+CRF解决NER问题
    word2vec训练&IC分词(待)
    tensorflow基础
    (转)pycharm快捷键
    Python包的相对导入时出现问题解决
    python工具使用笔记
  • 原文地址:https://www.cnblogs.com/shangxiaofei/p/14309067.html
Copyright © 2011-2022 走看看