Anoop
Anoop

Reputation: 913

Custom cookie name when using Spring 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.

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

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>

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

Upvotes: 2

Views: 4662

Answers (1)

Mark
Mark

Reputation: 29119

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>

Upvotes: 4

Related Questions