【发布时间】:2021-05-13 21:01:44
【问题描述】:
我们最近开始在我们的项目中集成 spring-session。这是一个基于 SOA 的应用程序,有一些逻辑实现来管理会话。
- HttpSessionListener 用于在超时情况下注销会话并通过 sessionDestroyed(HttpSessionEvent httpSessionEvent) 进行监控。
- 我们用来管理 HTTP 会话失效的 ServletRequestListener。这是在 requestDestroyed(ServletRequestEvent servletRequestEvent) 方法中实现的。
对于#1,我找到了一篇文章here,描述了Spring Session支持的SessionEventHttpSessionListenerAdapter的使用。并在我的 session.xml 中添加此配置。
<context:annotation-config/>
<bean class="org.springframework.session.hazelcast.config.annotation.web.http.HazelcastHttpSessionConfiguration"/>
<bean class="org.springframework.session.web.http.SessionEventHttpSessionListenerAdapter">
<constructor-arg>
<list>
<bean class="xxx.xxx.xxx.xxx.xxx.xxx.MyHttpSessionListener"/>
</list>
</constructor-arg>
</bean>
还在我的部署描述符中添加以下配置(例如 web.xml)
<filter>
<filter-name>springSessionRepositoryFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSessionRepositoryFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
经过一些调试,我注意到我的HttpSessionListener正在使用spring session提供的会话。
但是,对于第 2 项,使用 ServletRequestListener 实现,我找不到将其迁移到 Spring 会话的方法。它仍在使用容器提供的会话。
是否有用于 ServletRequestListener 的相应适配器,例如 SessionEventHttpSessionListenerAdapter? Spring Session 支持吗?为了让我们的功能与 Spring session 一起工作,我还有哪些其他选择?
【问题讨论】:
标签: spring-session servlet-listeners