1.pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
2.切入点、通知、切面
package cn.thuniwhir.fileserver.aspect;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class TestAop {
@Pointcut("execution(* cn.controller..*(..))")
public void testPointCut(){
}
@Around("testPointCut()")
public Object aroundTest(ProceedingJoinPoint point) throws Throwable {
System.out.println("==========around before");
Object result = point.proceed();
System.out.println("==========around after");
return result;
}
}
ProceedingJoinPoint