@Aspect @Component @Slf4j public class ControllerLogAspect { /** * 对所有的接口 添加日志 日志信息有 请求地址 被请求地址 请求参数 * * @param joinPoint */ @Before("@within(org.springframework.stereotype.Controller) || @within(org.springframework.web.bind.annotation.RestController)") public void restLogAccess(JoinPoint joinPoint) { ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); String url = requestAttributes.getRequest().getRequestURI(); String remoteAddr = requestAttributes.getRequest().getRemoteAddr(); log.info("[WEB] remoteAddr: {}, URL: {}, args: {}", remoteAddr, url, joinPoint.getArgs()); } }