不同场景下模拟session共享

本文介绍在同域名下,如何通过SpringSession实现多台Tomcat间Session共享,以及不同项目间的Session共享策略。通过设置Cookie路径为根上下文,实现跨项目Session共享。

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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值