使用Spring Session时的自定义Cookie名称 [英] Custom cookie name when using Spring Session

查看:4576
本文介绍了使用Spring Session时的自定义Cookie名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用v1.0.1的Spring Sessions。我有使用XML配置我的应用程序设置。我现在需要更改cookie名称从默认的SESSION基于一些属性。

I am using v1.0.1 of Spring Sessions. I have got my application setup using XML configurations. I now need to change the cookie name from the default of "SESSION" based on some property. For example to myApp_SESSION where myApp will be read from a property file.

我注意到 SessionRepositoryFilter 只有一个属性文件一个构造函数使用默认值接受 sessionRepository httpSessionStrategy CookieHttpSessionStrategy

I noticed that the SessionRepositoryFilter has only one constructor that takes a sessionRepository and the httpSessionStrategy with CookieHttpSessionStrategy using default values.

我当前的XML配置如下。

My current XML configuration is as below.

   <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豆更改cookie的名字吗?

Is it possible to change the cookie name by injecting a CookieHttpSessionStrategy to the springSessionRepositoryFilter bean?

推荐答案

您是正确的。它可能会注入一个CookieHttpSessionStrategy带有自定义cookie名称到SessionRepositoryFilter

You are correct. It is possible to inject a CookieHttpSessionStrategy with a custom cookie name into the 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>

这篇关于使用Spring Session时的自定义Cookie名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆