加入aop的jar
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
//代码如下
@Aspect
@Component
public class ServiceAspect {
Logger logger = LoggerFactory.getLogger(ServiceAspect.class);
@Pointcut("execution(* com.service.*.*.*ServiceImpl.*(..))")
private void pointCutMethodService(){
}
@Around("pointCutMethodService()")
public Object doAroundService(ProceedingJoinPoint pjp) throws Throwable{
long begin = System.nanoTime();
Object obj=pjp.proceed();
long end =System.nanoTime();
logger.info("调用Service方法:{},参数:{},执行耗时:{}纳秒,耗时:{}毫秒",
pjp.getSignature().toString(),Arrays.toString(pjp.getArgs()),(end-begin),(end-begin)/1000000);
return obj;
}
}