我正在使用 Spring Sessions v1.0.1。我已经使用 XML 配置设置了应用程序。我现在需要根据某些属性更改默认的“SESSION”cookie 名称。例如myApp_SESSION其中 myApp 将从属性文件中读取。
我注意到会话存储库过滤器只有一个构造函数需要一个会话存储库和httpSession策略 with CookieHttpSession策略使用默认值。
我当前的 XML 配置如下。
<bean id="mapSessionRepository" class="org.springframework.session.MapSessionRepository" />
<bean id="springSessionRepositoryFilter" class="org.springframework.session.web.http.SessionRepositoryFilter">
<constructor-arg ref="mapSessionRepository" />
</bean>
是否可以通过将 CookieHttpSessionStrategy 注入 springSessionRepositoryFilter bean 来更改 cookie 名称?
你是对的。可以将带有自定义 cookie 名称的 CookieHttpSessionStrategy 注入 SessionRepositoryFilter。
<bean id="sessionRepositoryFilter"
class="org.springframework.session.web.http.SessionRepositoryFilter">
<constructor-arg ref="sessionRepository"/>
<property name="httpSessionStrategy">
<bean class="org.springframework.session.web.http.CookieHttpSessionStrategy">
<property name="cookieName" value="myCookieName" />
</bean>
</property>
</bean>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)