一、在 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帶的會話進行封裝,接管會話