惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Blog — PlanetScale
Blog — PlanetScale
G
Google Developers Blog
Microsoft Security Blog
Microsoft Security Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
腾讯CDC
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Jina AI
Jina AI
雷峰网
雷峰网
T
Tailwind CSS Blog
爱范儿
爱范儿
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
大猫的无限游戏
大猫的无限游戏
月光博客
月光博客
博客园 - 司徒正美
I
InfoQ
Engineering at Meta
Engineering at Meta
Vercel News
Vercel News
小众软件
小众软件
U
Unit 42
Google DeepMind News
Google DeepMind News
D
DataBreaches.Net

祈雨的笔记

安全多方计算MPC spark原理解析 kueue执行源码分析 spark on k8s执行源码分析 spark-operator源码解析 系统压测遇到的缓存击穿问题 我的世界PC与安卓联机 蚂蚁金服流量投放平台的AIG改造 G1大对象致Old区占用率高 日志打印导致接口响应率下跌分析 Groovy加载类导致OOM分析 ERROR日志打印导致CPU满载 记OceanBase死锁超时 应用发版期间服务响应超时 Ark Serverless初探 系统优化复盘一二三 The user specified as a definer does not exist Kong网关初探 API网关选型调研 CPU火焰图常用工具 配置中心选型调研 root操作Nginx导致用户组错误 基于Proxifier使用代理 FastJSON字段智能匹配踩坑 Nacos初探 记一次Nginx服务器CPU满荷载故障 基于券系统分库分表的思考 limit不参与SQL成本计算致索引失效 Linux常用性能监控命令 golang低版本http2偶现400
springboot(5)AOP代理
祈雨的笔记 · 2018-01-22 · via 祈雨的笔记

1、启动aop代理

添加maven依赖

1
2
3
4
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>

向springboot的入口类添加注解@EnableAspectJAutoProxy,使注解@Aspect生效。

2、aspect代理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
@Aspect
@Component
public class TestAspect {




@Before("execution(* com.example.demo.action.*.* (..))")
public void testBefore() {
System.out.println("before");
}




@After("execution(* com.example.demo.action.*.* (..))")
public void testAfter() {
System.out.println("after");
}






@Around("execution(* com.example.demo.action.*.* (..))")
public Object testAround(ProceedingJoinPoint pjp) throws Throwable {

System.out.println("before");

Object result = pjp.proceed();
System.out.println("==========="+result);

System.out.println("after");
return result;
}





@AfterThrowing(pointcut="execution(* com.example.demo.action.*.* (..))",throwing="e")
public void testThrowing(Exception e) {
System.out.println(e.getMessage());
}
}

3、pointcut表达式

常用的pointcut表达式为execution,格式如下:
execution([访问修饰符] 返回类型 [申明类型] 方法名(参数名) [异常名])
|表达式|效果|
|—–|—–|—–|
|execution(public * * (..))|任意公共方法|
|execution(* set* (..))|任意方法名以”set”开头的方法|
|execution(* com.wxtx.TestDao.* (..))|com.wxtx.TestDao类下的任意方法|
|execution(* com.wxtx.. (..))|com.wxtx包(不包括子包)下的任意方法|
|execution(* com.wxtx... (..))|com.wxtx包及其子包下的任意方法|
|within(com.wxtx.service.)|com.wxtx.service包(不包括子包)下的任意方法|
|within(com.wxtx.service..
)|com.wxtx.service包(不包括子包)下的任意方法|
|this(com.wxtx.service.TestService)|实现了com.wxtx.service.TestService接口的代理对象的任意方法|
|target(com.wxtx.service.TestService)|实现了com.wxtx.service.TestService接口的目标对象的任意方法|
|args(java.io.Serializable)|任意只接受一个参数,且该参数类型是java.io.Serializable的方法|
|bean(testService)|spring容器中bean名为testSerivce的bean的任意方法|
|bean(Service)|spring容器中bean名匹配Serivce的bean的任意方法|