导入相关依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<version>2.4.2</version>
</dependency>
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
import java.util.concurrent.locks.ReentrantLock;
@Component
@Aspect //标注这是个切面类
public class AnnotationPointCut {
@Before("execution(* com.kun.springboot01helloworld.config.testconfg.add())")
private void before(){
System.out.println("======方法执行前===============");
}
@After("execution(* com.kun.springboot01helloworld.config.testconfg.add())")
private void after(){
System.out.println("======方法执行后===============");
}
@Around("execution(* com.kun.springboot01helloworld.config.testconfg.*(..))")
//@Around("execution(* com.kun.springboot01helloworld.config.testconfg.*(..))")
private void around(ProceedingJoinPoint jp) throws Throwable {
System.out.println("======环绕前===============");
System.out.println(jp.getSignature());//获得调用的具体类
System.out.println("======环绕后===============");
jp.proceed();//执行方法
}
}