package com.example.jz.aop;
|
|
import lombok.extern.log4j.Log4j2;
|
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;
|
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@Aspect
|
@Component
|
@Log4j2
|
public class InterfaceLogHandler {
|
|
@Pointcut("execution(* com.example.jz.controller.*.*(..))")
|
public void pointcut(){};
|
|
@Before("pointcut()")
|
public void log(JoinPoint joinPoint){
|
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
HttpServletRequest request = attributes.getRequest();
|
log.info("访问接口:{}",request.getRequestURI());
|
}
|
|
}
|