01 | package com.kaka.aop; |
02 |
03 | import org.aopalliance.intercept.MethodInterceptor; |
04 | import org.aopalliance.intercept.MethodInvocation; |
05 |
06 | /** |
07 | * 被监控的方法在被调用之前都会进入invoke方法 |
08 | * |
09 | * |
10 | * @author kaka |
11 | * |
12 | */ |
13 | public class HeartBeatAop implements MethodInterceptor{ |
14 |
15 | @Override |
16 | public Object invoke(MethodInvocation invocation) throws Throwable { |
17 | /** |
18 | * 监控heartBeat方法,在调用heartBeat方法之前和之后做一些其他操作 |
19 | */ |
20 | |
21 | //1.获得被监控方法的参数列表,此时heartBeat方法还没有被调用,这时候就可以根据业务需求做一些其他的操作 |
22 | Object[] arguments = invocation.getArguments(); |
23 | System.out.println( "heartBeat方法的参数是:" +arguments[ 0 ]); |
24 | //2.调用heartBeat方法 |
25 | Object result = invocation.proceed(); |
26 | //3.方法结束后的一些操作 |
27 | System.out.println( "监控heartBeat结果:" +result); |
28 | |
29 | return result; //此处的返回值对应被监控方法的返回值 |
30 | } |
31 |
32 | } |


2636804923 LV6
2024年6月16日
李朝磊 LV18
2024年6月13日
1358849392 LV21
2024年1月22日
女王不该在山炮村养花 LV8
2023年4月6日
猴子蹲蹲 LV2
2023年4月6日
我就一大帅比
2023年2月16日
暂无贡献等级
00044304 LV6
2022年8月24日
wxh1234567 LV4
2022年1月17日
阿远远 LV8
2021年11月26日
cenj12700 LV5
2021年8月13日