问题
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?
回答1:
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>
来源:https://stackoverflow.com/questions/29964921/custom-cookie-name-when-using-spring-session