当前位置:网站首页>相同切入点的抽取
相同切入点的抽取
2022-07-03 16:01:00 【不入开发不工作】
1.相同切入点的抽取
抽取前:
package com.spring.spring5.annotaion;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
//增强的类
@Aspect//表示生成代理对象
@Component
public class UserProxy {
//前置通知
@Before(value = "execution(* com.spring.spring5.annotaion.User.add(..))")//表示作为前置通知
public void before(){
System.out.println("Before......");
}
//最终通知,不管有没有异常在方法之后都执行
@After(value = "execution(* com.spring.spring5.annotaion.User.add(..))")
public void after(){
System.out.println("After......");
}
//后置通知(返回通知),方法无异常结束时执行
@AfterReturning(value = "execution(* com.spring.spring5.annotaion.User.add(..))")
public void afterReturning(){
System.out.println("AfterReturning......");
}
//异常通知,add()有异常时才会执行
@AfterThrowing(value = "execution(* com.spring.spring5.annotaion.User.add(..))")
public void afterThrowing(){
System.out.println("AfterThrowing......");
}
//环绕通知,在方法之前和之后执行
@Around("execution(* com.spring.spring5.annotaion.User.add(..))")
public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
System.out.println("Around之前......");
proceedingJoinPoint.proceed();
System.out.println("Around之后......");
}
}
抽取后:
package com.spring.spring5.annotaion;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
//增强的类
@Aspect//表示生成代理对象
@Component
public class UserProxy {
//相同切入点抽取
@Pointcut("execution(* com.spring.spring5.annotaion.User.add(..))")
public void pointdemo() {
}
//前置通知
@Before(value = "pointdemo()")//表示作为前置通知
public void before(){
System.out.println("Before......");
}
//最终通知,不管有没有异常在方法之后都执行
@After(value = "pointdemo()")
public void after(){
System.out.println("After......");
}
//后置通知(返回通知),方法无异常结束时执行
@AfterReturning(value = "pointdemo()")
public void afterReturning(){
System.out.println("AfterReturning......");
}
//异常通知,add()有异常时才会执行
@AfterThrowing(value = "pointdemo()")
public void afterThrowing(){
System.out.println("AfterThrowing......");
}
//环绕通知,在方法之前和之后执行
@Around("pointdemo()")
public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
System.out.println("Around之前......");
proceedingJoinPoint.proceed();
System.out.println("Around之后......");
}
}
两者效果一致
边栏推荐
- WinDbg analysis dump file
- Microservice - Nacos registration center and configuration center
- Function introduction of JMeter thread group
- String functions that you need to know
- Microservices - load balancing ribbon
- Unity功能——Unity离线文档下载及使用
- VC下Unicode和ANSI互转,CStringW和std::string互转
- Custom annotation
- Microservice - fuse hystrix
- 无心剑中译泰戈尔《漂鸟集(1~10)》
猜你喜欢
Q2 encryption market investment and financing report in 2022: gamefi becomes an investment keyword
WinDbg analysis dump file
找映射关系
Seckill system 2 redis solves the problem of distributed session
Asemi rectifier bridge umb10f parameters, umb10f specifications, umb10f package
“用Android复刻Apple产品UI”(3)—优雅的数据统计图表
Seckill system 3- product list and product details
Mongodb installation and basic operation
CString getbuffer and releasebuffer instructions
Vs2017 is driven by IP debugging (dual machine debugging)
随机推荐
[combinatorics] combinatorial identity (sum of variable upper terms 1 combinatorial identity | summary of three combinatorial identity proof methods | proof of sum of variable upper terms 1 combinator
分布式事务(Seata) 四大模式详解
初试scikit-learn库
大csv拆分和合并
嵌入式开发:避免开源软件的7个理由
ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装
Get the executable path through the process PID (queryfullprocessimagename)
坚持输出需要不断学习
CString在多线程中的问题
Famous blackmail software stops operation and releases decryption keys. Most hospital IOT devices have security vulnerabilities | global network security hotspot on February 14
The difference between calling by value and simulating calling by reference
Large CSV split and merge
Expression of request header in different countries and languages
MB10M-ASEMI整流桥MB10M
潘多拉 IOT 开发板学习(HAL 库)—— 实验5 外部中断实验(学习笔记)
Batch files: list all files in a directory with relative paths - batch files: list all files in a directory with relative paths
CString的GetBuffer和ReleaseBuffer使用说明
使用AUR下载并安装常用程序
From the 18th line to the first line, the new story of the network security industry
Under VC, Unicode and ANSI are converted to each other, cstringw and std:: string are converted to each other