在登錄完成后需要記錄登錄結果,其中一項包含客戶端的IP地址,但是一直取不到值,通過排查發現,RequestContextHolder.getRequestAttributes()
值為空,因為獲取ip是在主線程進行的,所以排除線程共享的問題,然后互聯網搜索了一下,需要加一段代碼
@Bean
public RequestContextListener requestContextListener(){
return new RequestContextListener();
}
試了一下,確實問題解決了,不過對RequestContextListener
不熟悉,不知道具體做了啥,所以又繼續搜索,找到了一篇文章
ContextLoaderListener與RequestContextListener配置問題
簡單了解了一下,OK,收獲知識➕1,問題解決