依赖org.springframework.bootspring-boot-starter-aopAOP详解常用动态代理技术JDK代理:基于接口的动态代理technologyCGLIB代理:基于父类的动态代理技术(默认)1.beforenotification在执行目标方法前执行2.afterRhrowing通知在目标方法执行后执行3.afterReturning通知在执行完后报错时执行targetmethodisexecuted4.afternotificationregardless程序执行完成时必须执行的通知5.Aroundnotification(最强大的功能)在target方法执行前后执行,因为周围通知可以控制target是否执行方法执行,控制程序的执行轨迹入口点表达式1、bean("beanID")粒度:粗粒度,根据当前bean中匹配该方法的bean执行通知2,在(“包裹名字。类名")粒度:粗粒度可以匹配多个类名.类名.方法名(参数列表)")粒度:细粒度方法参数级别4,@annotation("包名.类名")粒度:粗粒度-grained根据注解匹配示例@Aspect//将当前类标识为Anaspect,供容器读取@Component//交给springboot管理publicclassCommonAop{//Pointcut是植入Advice的触发条件//within("包名.类名")粒度:粗粒度可以匹配多个Class@Pointcut("within(com.hj.controller.LogController)")publicvoidoneAop(){}//within("包名.类名")粒度:粗粒度匹配多个类@Pointcut("within(com.hj.controller.LogController)||within(com.hj.controller.StudentController)")publicvoidtwoAop(){}//execution("返回值类型包名.类名.方法名(参数列表)")粒度:细粒度的方法参数级参数列表可以使用*代替多个参数@Pointcut("execution(*com.hj.controller.StudentController.selectAll())")publicvoidthreeAop(){}//@annotation("Annotation")调用注解匹配@Pointcut("@annotation(org.springframework.web.bind.annotation.GetMapping)")publicvoidfourAop(){}@Around("oneAop()")publicObjectaround(ProceedingJoinPointjoinPoint)throwsThrowable{System.out.println("Around开始执行");对象proceed=joinPoint.proceed();System.out.println("环绕执行完成");返回进行;}@AfterReturning("threeAop()")publicObjectafterReturning(ProceedingJoinPointjoinPoint)throwsThrowable{System.out.println("AfterReturning开始");对象proceed=joinPoint.proceed();System.out.println("返回完成");返回进行;}}