首页 > 其他 > 详细

AOP案例(一)

时间:2019-12-13 22:08:35      阅读:122      评论:0      收藏:0      [点我收藏+]

package com.jt.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class RuntimeAOP {

@Around("execution(* com.jt.service..*.*(..))")
public Object around(ProceedingJoinPoint joinPoint) {
Object obj=null;
Long starttime=System.currentTimeMillis();
try {
obj=joinPoint.proceed();
} catch (Throwable e) {
e.printStackTrace();
throw new RuntimeException(e);
}
Long endtime=System.currentTimeMillis();
Class<?> targetclass = joinPoint.getTarget().getClass();
String methodName = joinPoint.getSignature().getName();

System.out.println("目标的对象类型:"+targetclass);
System.out.println("目标方法的名称:"+methodName);
System.out.println("RuntimeAOP[] 执行时间:"+(endtime-starttime)+"毫秒");

return obj;
}
}

AOP案例(一)

原文:https://www.cnblogs.com/lizhiwei666/p/12037273.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!