一、在 pom.xml添加springsession
<! - springsession-> <dependency> <groupId> org.springframework.session </groupid> <Artifactid> spring-session-session-data-redis </artifactid> </artifactid> <版本> 1.2.0.Release </distrace </distrace> </depentency>
二、确保春季是4.3.10.Release版本以上
<依赖项> <groupId> org.springframework </groupId> <ArtifactId> spring-context </artifactid> </artifactid> <版本> 4.3.10.Release </version </version> </distionency>
三、 applicationContext.xml文件中添加四个bean类
<bean id =“ redishttpsessessconfiguration”> <属性名称=“ maxinactiveInterValinSeconds” value =“ 180”> </bean> </bean> </bean> <bean id =“ jedispoolConfig”> </bean> </bean> <ehbean iD =“ jedisconnectionfactoryfactory” value =“ 6379”> </属性> <属性名称=“ poolconfig” ref =“ jedispoolConfig”> </property> </bean> </bean> <bean id =“ defaultCookieserializer”> <property name =“ cookiename” value =“ value =” value =“ springsession”在
这样就可以实现会话共享,nginx下的tomcat集群也是这样的
原理就是:通过springsession对servlet带的会话进行封装,接管会话