SpringBoot启动流程分析知识点--AOP(二)

本文详细分析了Spring Boot启动流程中的AOP组件,包括Aspect、Pointcut、Advice、Advisor和Advised的概念及其相互关系。Aspect结合了切入点和通知,Pointcut定义匹配点,Advice定义增强逻辑,Advisor是Pointcut和Advice的组合,而Advised则代表了已织入的代理对象。文中还提及了@AspectJ和Advisor的区别以及它们在实际应用中的转换过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

SpringBoot启动流程分析知识点–AOP(二)

一、概述

源码基于SpringBoot 2.7.xx版本

官网:SpringBoot–aop

1.1 简介

上一节中介绍了在创建AOP代理对象时会先获取当前bean的Advices和Advisors,本节介绍Spring
AOP组件中的Aspect、Pointcut、Advice、Advisor、Advised。

1.2 Spring AOP组件

  1. Aspect

    • “切面”,切⾯(Aspect)由多个切入点(Pointcut)和多个通知(Advice)组成。
    • 注解所在的包为–org.aspectj.lang.annotation.Aspect。
  2. Pointcut

    “切入点”,它的作用就是定义切面的匹配点。(简单的说就是我去切哪些类、哪些方法…) 在 Spring Aop 中匹配的点主要是 class 与
    method 这两个方面,分别为ClassFilter 与 MethodMatcher。

    • 注解所在的包为–org.aspectj.lang.annotation.Pointcut。
    • 最终转换为Spring中的对象–org.springframework.aop.Pointcut。
    目前Spring支持的切点匹配表达式主要有以下几种:
    execution:可以定义到的最小粒度是方法,修饰符,包名,类名,方法名,Spring AOP主要也是使用这个匹配表达式;
    within:只能定义到类;例如@Pointcut(within(com.jnu.example.*))
    this:当前生成的代理对象的类型匹配;
    target:目标对象类型匹配;
    args:只针对参数;
    annotation:针对注解;
    
  3. Advice

    “通知”,需要执行的增强逻辑方法。包括 “around”, “before” and “after 等。

    • 注解所在的包为–org.aspectj.lang.annotation.Around。
      • 最终转换为Spring中的对象–org.springframework.aop.aspectj.AspectJAroundAdvice。
    • 注解所在的包为–org.aspectj.lang.annotation.Before。
      • 最终转换为Spring中的对象–org.springframework.aop.aspectj.AspectJMethodBeforeAdvice。
    • 注解所在的包为–org.aspectj.lang.annotation.After。
      • 最终转换为Spring中的对象–org.springframework.aop.aspectj.AspectJAfterAdvice。
    • 注解所在的包为–org.aspectj.lang.annotation.AfterReturning。
      • 最终转换为Spring中的对象–org.springframework.aop.aspectj.AspectJAfterReturningAdvice。
    • 注解所在的包为–org.aspectj.lang.annotation.AfterThrowing。
      • 最终转换为Spring中的对象–org.springframe
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fanderboy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值