标签:log 的区别 自动 ble nbsp mes back color col
上上偏博客介绍了@Aspect,@Before
上篇博客介绍了spring的AOP开发的注解通知类型:@Before,@AfterThrowing,@After,@AfterReturning,@Around
也介绍了JoinPoint和ProceedingJoinPoint的区别
这篇博客讲@PointCut的使用,切入点注解----转载自https://www.cnblogs.com/ltfxy/p/9885742.html
这种方法便于维护管理
/** * 切面类:注解的切面类 */ @Aspect public class MyAspectAnno { //切入点的注解 @Pointcut(value="execution(* com.itheima.spring.demo1.OrderDao.find(..))") private void pointcut1(){} @Pointcut(value="execution(* com.itheima.spring.demo1.OrderDao.save(..))") private void pointcut2(){} @Pointcut(value="execution(* com.itheima.spring.demo1.OrderDao.update(..))") private void pointcut3(){} @Pointcut(value="execution(* com.itheima.spring.demo1.OrderDao.delete(..))") private void pointcut4(){} //前置通知 @Before(value="MyAspectAnno.pointcut2()") public void before(){ System.out.println("前置通知======"); } //后置通知 @AfterReturning(value="MyAspectAnno.pointcut4()", returning="result") public void afterReturning(Object result){ System.out.println("后置通知====="+result); } //环绕通知 @Around(value="MyAspectAnno.pointcut3()") public Object around(ProceedingJoinPoint joinPoint) throws Throwable{ System.out.println("环绕前增强====="); Object obj = joinPoint.proceed(); System.out.println("环绕后增强====="); return obj; } //异常抛出通知 @AfterThrowing(value="MyAspectAnno.pointcut1()" , throwing="e") public void find(Throwable e ){ System.out.println("异常抛出通知======"+e.getMessage()); } // 最终通知: @After(value="MyAspectAnno.pointcut1()") public void after( ){ System.out.println("最终通知======"); } }
当使用接口的时候,spring会自动采用JDK的动态代理
不使用接口的话,spring会自动采用Cglib的动态代理
标签:log 的区别 自动 ble nbsp mes back color col
原文地址:https://www.cnblogs.com/zengcongcong/p/10364956.html