一、在 Pom.xml 添加 Springsession
<!-Springsessession-> <Dependency> <groupId> org.springframework.session </GroupId> <strifactId> Spring-session-data-redis </artifactid> <sersive> 1.2.0.release </version> </depervice>
二、确保 Spring 是 4.3.10.Eredease 版本以上
<depervice> <groupid> org.springframework </groupid> <artifactid> spring-context </artifactid> <sersive> 4.3.10.release </version> </deperency>
三、 ApplicationContext.xml 文件中添加四个 Bean 类
<bean id = "redishttpsessionConfiguration"> <name = "maxinactiveIntervalinseconds" value = "180"> </property> </bean> <bean id = "jedispoolconfig"> </bean> <bean id = "jedisconnectionfact"> property name = "hostname". name = "port" value = "6379"> </property> <Property name = "poolconfig" ref = "jedispoolconfig"> </property> </bean> <bean id = "defaulcookieserializer"> <свойство = "cookiename" value = "springsession"> </property name = "cookiePath" = "/"/"/" Propect -name "cookiePath" = "/"/"/" Property -name ". value = "3600"/> <name = "usehttponlycookie" value = "true"/> <name = "domainname" value = ". qs.com"/> </bean>
这样就可以实现 сеанс 享享 , nginx 下的 Tomcat 集群也是这样的
原理就是 : 通过 Springsession 对 Сервлет 带的 Session 进行封装 , 接管 Session