1 .同域名下相同项目实现Session共享
在同一个域名下,比如:www.p2p.com
同一个项目;
部署了多台tomcat;
这就是典型的集群;
利用springsession实现多台tomcat session共享
2、同域名下不同项目实现Session共享
在同一个域名下,比如:
www.web.com/jiekuan
www.web.com/touzi
做法:设置Cookie路径为根/上下文;
<!-- Spring session 的配置类 -->
<bean class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
<property name="maxInactiveIntervalInSeconds" value="1800"/>
<property name="httpSessionStrategy" ref="cookieHttpSessionStrategy"/>
</bean>
<!--cookie的策略-->
<bean id="cookieHttpSessionStrategy" class="org.springframework.session.web.http.CookieHttpSessionStrategy">
<property name="cookieSerializer" ref="defaultCookieSerializer"/>
</bean>
<!--设置cookie信息-->
<bean id="defaultCookieSerializer" class="org.springframework.session.web.http.DefaultCookieSerializer">
<!--设置cookie存放在跟的上下文路径-->
<property name="cookiePath" value="/" />
</bean>