pom.xml中加入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
然后写入一个类就可以了 我的是实现记录实现层方法selectAll调用次数
/**
* Create Date:2019年6月18日
*/
package com.kh.aop;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
/**
* <br>Title:TODO 类标题
* <br>Description:TODO 类功能描述
* <br>Author:kk
* <br>Date:2019年6月18日
*/
@Aspect
@Component
public class MyAspect {
private int i = 0;
@Pointcut(value = "execution(* com.kh.service.impl.*.*(..))")
public void log() {
}
@Before("log()")
public void deBefore(JoinPoint joinPoint) {
String name = joinPoint.getSignature().getName();
if (name.equals("selectAll")) {
i++;
}
System.out.println("----------------------------------------" + name + "调用次数" + i);
}
}