springboot aop为什么RequestContextHolder.getRequestAttributes()返回空

使用springboot AOP获取请求信息使用ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
方法饭后空指针

@Aspect
@Component
public class LogAspect
{
private static Logger LOG = LogManager.getLogger(LogAspect.class);

@Pointcut("execution(* com.asiainfomsp.cloud.cube..*.*(..))")
public void LogAspect()
{
    LOG.info("开始记录日志");
}

@Around("LogAspect()")
public void doBefore(ProceedingJoinPoint joinPoint){
    LOG.info("doBefore----");
    ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();
        LOG.info("method :[{}]",request.getMethod());
        LOG.info("uri :[{}]",request.getRequestURI());
        LOG.info("Host :[{}]",request.getRemoteHost());
        LOG.info("addr :[{}]",request.getRemoteAddr());
        LOG.info("port :[{}]",request.getRemotePort());

}

}


Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问