一、在 pom.xml 添加 Springsession
<!-SpringSession-> <dependency> <GroupId> org.springframework.Session </proupId> <ArtifactId> pegas-sesi-data-redis </RiTtifacTID> <Version> 1.2.0.Release </version> </Dependency>
二、确保 Spring 是 4.3.10.Release 版本以上
<dependency> <GroupId> org.springframework </groupId> <ArTifactId> Spring-Context </artifactid> <version> 4.3.10.release </version> </dependency>
三、 ApplicationContext.xml 文件中添加四个 Bean 类
<bean id = "redishttpsessionConfiguration"> <properti name = "maxInactiveInterValInconds" value = "180"> </propert> </tact> <bean id = "jedaispoolconfig"> </bean> <bean id = "jedisconnectionFactory"> </host name = "host =" 12.0. name = "port" value = "6379"> </property> <properti name = "poolconfig" ref = "jedispoolconfig"> </preate> </ bean> <bean id = "defaultcookieserializer"> <nama properti = "cookiene" value = "springsesi"> </property> <Property name = "cookiePath =" cookiene "value =" springsesi "> </property> <Property name =" cookiePath "=" cookiene "=" springsesi "> </property> property name =" cookiePath "=" cookiLe "=" SpringSesi "> </Property> Properties =" CookIePath "name =" cookiLe "value" " value = "3600"/> <name properti = "useHttponlycookie" value = "true"/> <name properti = "domainname" value = ". qs.com"/> </ bean>
这样就可以实现 Sesi 享 , nginx 下的 tomcat 集群也是这样的
原理就是 : 通过 Springsession 对 Servlet 带的 Sesi 进行封装 , 接管 Sesi