1、创建类,在类里面定义方法
2、创建增强类(编写增强逻辑)
①在增强类里面,创建方法,让不同方法代表不同的通知类型
3、进行通知的配置
①在spring配置文件中,开启注解扫描
②使用注解创建User和UserProxy对象

③在增强类上面添加注解@Aspect
④在spring配置文件中开启生成代理对象
4、配置不同类型的通知
①在增强类的里面,在作为通知方法上面添加通知类型注解,使用切入点表达式配置


*测试**

package com.atguigu.spring5.AOPanno;import org.aspectj.lang.ProceedingJoinPoint;import org.aspectj.lang.annotation.After;import org.aspectj.lang.annotation.AfterReturning;import org.aspectj.lang.annotation.AfterThrowing;import org.aspectj.lang.annotation.Around;import org.aspectj.lang.annotation.Aspect;import org.aspectj.lang.annotation.Before;import org.springframework.stereotype.Component;/*** @author Dxkstart* @create 2021-10-29-19:04*///增强的类@Component@Aspect //生成代理对象public class UserProxy {//前置通知//@before注解表示作为前置通知@Before(value = "execution(* com.atguigu.spring5.AOPanno.User.add(..))")public void before() {System.out.println("前置通知before........");}//最终通知//方法之后执行@After(value = "execution(* com.atguigu.spring5.AOPanno.User.add(..))")public void after() {System.out.println("最终通知after......");}//后置通知(返回通知)//方法返回了值之后执行@AfterReturning(value = "execution(* com.atguigu.spring5.AOPanno.User.add(..))")public void afterReturning() {System.out.println("后置通知afterReturning.......");}//异常通知@AfterThrowing(value = "execution(* com.atguigu.spring5.AOPanno.User.add(..))")public void AfterThrowing() {System.out.println("异常通知AfterThrowing.....");}//环绕通知@Around(value = "execution(* com.atguigu.spring5.AOPanno.User.add(..))")public void Around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {System.out.println("环绕之前........");//被增强的方法执行proceedingJoinPoint.proceed();System.out.println("环绕之后........");}}
