RequestContextHolder.getRequestAttributes()为空的问题

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

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

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

上一篇:SpringMVC之RequestContextHolder分析


下一篇:如何用 Python 发送告警通知到微信?