1.安装依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
2.定义切面、切点设置通知
@Aspect
@Component
public class AopConfig {
//设置切点为controller下的所有方法,该表达式为 com.springboot.controller包下的所有类和所有方法
@Pointcut("execution (* com.springboot.controller.*.*(..))")
public void logInfo() {
}
@Before("logInfo()")
public void beforeAdvice(JoinPoint jp) {
System.out.println("beforeAdvice...");
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
Http