spring学习笔记(19)——重用切点表达式
来源:互联网 发布:java中scaner的next 编辑:程序博客网 时间:2024/05/02 08:18
重用切点表达式
先看看之前的代码
@Aspect@Componentpublic class LoggingAscept { @Before("execution(* com.zj.asceptj.*.*(..))") public void beforeMethod(JoinPoint joinpoint){ //注意,JoinPoint来自org.aspectj.lang.JoinPoint,小心导错包 //方法名 String methodName = joinpoint.getSignature().getName(); //方法参数 List<Object> args = Arrays.asList(joinpoint.getArgs()); System.out.println("method "+methodName+" begin:"+args); } @After("execution(* com.zj.asceptj.*.*(..))") public void afterMethod(JoinPoint joinpoint){ //注意,JoinPoint来自org.aspectj.lang.JoinPoint,小心导错包 //方法名 String methodName = joinpoint.getSignature().getName(); //方法参数 List<Object> args = Arrays.asList(joinpoint.getArgs()); System.out.println("method "+methodName+" end:"+args); }}
在每一个通知中的
execution(* com.zj.asceptj.*.*(..))
几乎都是一致的,我们希望能够重用起来,也便于后期的维护
@Aspect@Componentpublic class LoggingAscept { /** * 声明切点表达式 */ @Pointcut("execution(* com.zj.asceptj.*.*(..))") public void declareJoinPointExpression(){} @Before("declareJoinPointExpression()") public void beforeMethod(JoinPoint joinpoint){ //注意,JoinPoint来自org.aspectj.lang.JoinPoint,小心导错包 //方法名 String methodName = joinpoint.getSignature().getName(); //方法参数 List<Object> args = Arrays.asList(joinpoint.getArgs()); System.out.println("method "+methodName+" begin:"+args); } @After("declareJoinPointExpression()") public void afterMethod(JoinPoint joinpoint){ //注意,JoinPoint来自org.aspectj.lang.JoinPoint,小心导错包 //方法名 String methodName = joinpoint.getSignature().getName(); //方法参数 List<Object> args = Arrays.asList(joinpoint.getArgs()); System.out.println("method "+methodName+" end:"+args); }}
如果在其他的切面中使用,加上类名即可,例如在ValidateAspect中
@After("LogginAspect.declareJoinPointExpression()")
如果在不同包中,类名前再加上包名即可
0 0
- spring学习笔记(19)——重用切点表达式
- spring学习笔记十六 重用切点表达式
- spring学习笔记(21)----重用切点表达式
- 19.Spring学习笔记_重用切点表达式(by尚硅谷_佟刚)
- @Pointcut——切点表达式重用
- Spring中切点表达式的重用
- Spring-AOP:切面优先级和重用切点表达式
- 14.Spring_重用切点表达式
- Spring源码学习笔记(四)-Aop获取增强、切点
- spring aop 切点表达式
- spring学习笔记(11)@AspectJ研磨分析[2]切点表达式函数详解
- spring的返回通知、异常通知、环绕通知、切面的优先级与重用切点表达式
- Spring AOP学习笔记(4):AOP切面优先级&切面表达式重用&xml配置方式
- spring aop切点表达式函数
- Spring中aop切点表达式
- Spring AOP切点表达式函数
- [Spring]Spring AOP学习笔记(2)---5种切入方式、AOP优先级及切面表达式的重用
- Spring学习-19:Spring的AOP:带有切点的切面
- 第43课第四题
- 更新hosts文件的python脚本
- 开源镜像站一些地址和寻找方法
- spring依赖注入(2)-注解
- 树状数组区间求和三种模型
- spring学习笔记(19)——重用切点表达式
- Xcode clang-omp openmp开发
- 日经春秋 20150509
- 欢迎使用CSDN-markdown编辑器
- spring依赖注入(3)-autowire
- Mysql设置某字段唯一
- 日经社説 20150509 トヨタは再び成長できるか
- 【C++】一些基本的运算符的重载
- 杭州最好的狐臭医院_杭州去狐臭最好的医院_腋臭治疗