Custom cookie name when using a Spring session

I am using v1.0.1 from Spring sessions. I have set up my application using XML configurations. Now I need to change the default cookie name "SESSION" based on some property. For example, in myApp_SESSION, where myApp will be read from the properties file.

I noticed that SessionRepositoryFilter has only one constructor that accepts SessionRepository and httpSessionStrategy with CookieHttpSessionStrategy using default values.

My current XML configuration is 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 name of the cookie by entering CookieHttpSessionStrategy in the springSessionRepositoryFilter bean?

0
source share
1 answer

You're right. You can add a CookieHttpSessionStrategy with a custom cookie name in 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> 
+2
source

Source: https://habr.com/ru/post/1210401/


All Articles