【发布时间】:2015-01-17 04:30:48
【问题描述】:
我希望将一些客户端信息(IP 地址等)保存到 Spring MVC 中创建的会话的数据库中。
我创建了一个实现 HttpSessionListener 的类,并在 web.xml 中对其进行了配置。但是,我不确定在那之后去哪里。
也希望能够注入一个 bean(Spring Data JPA 存储库)。
我见过 How to get the IP address when a session is created? ,但是如果我尝试访问 RequestContextHolder.currentRequestAttributes() 我得到以下异常:
SEVERE: Session event listener threw exception
java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
【问题讨论】:
标签: session spring-mvc ip-address