一、在 pom.xml 添加 Springsession
<!-SpringSession-> <Depency> <PuerpId> org.springframework.session </foupiD> <TRATIFACTID> Spring-session-data-redis </sutifactId> <versão> 1.2.0.release </sisters> </pendence>
Spring 是 4.3.10. Release 版本以上
<Depencency> <PuerpId> org.springframework </frugiD> <TRAFACTID> Spring-Context </ArtifactId> <versão> 4.3.10.release </sipers> </dependency>
三、 ApplicationContext.xml 文件中添加四个 Bean 类
<bean id = "RedishttpSessionConfiguration"> <propriedade name = "maxinactiveInterValInseconds" value = "180"> </propriedade> </bean> <bean id = "jedispoolconfig"> </bean> <bean id = "jedisconnectionFactory"> <erpown> hostname "". valor value = "3600"/> <propriedade name = "usehtttonlycookie" value = "true"/> <propriedade name = "domainname" value = ".
这样就可以实现 Sessão 享享 , nginx 下的 tomcat 集群也是这样的
原理就是 : 通过 Springsession 对 Servlet 带的 Sessão 进行封装 , 接管 Sessão