其他分享
首页 > 其他分享> > RequestContextHolder.getRequestAttributes()为空的问题

RequestContextHolder.getRequestAttributes()为空的问题

作者:互联网

在登录完成后需要记录登录结果,其中一项包含客户端的IP地址,但是一直取不到值,通过排查发现,RequestContextHolder.getRequestAttributes()值为空,因为获取ip是在主线程进行的,所以排除线程共享的问题,然后互联网搜索了一下,需要加一段代码

@Bean
public RequestContextListener requestContextListener(){
    return new RequestContextListener();
}

试了一下,确实问题解决了,不过对RequestContextListener不熟悉,不知道具体做了啥,所以又继续搜索,找到了一篇文章
ContextLoaderListener与RequestContextListener配置问题
简单了解了一下,OK,收获知识➕1,问题解决

标签:RequestContextHolder,RequestContextListener,getRequestAttributes,问题,登录,搜索,为空
来源: https://www.cnblogs.com/redos/p/14945483.html