一、Jar包引用
我们目前使用的spring版本是如下
org.springframework.version----4.3.15.RELEASE
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
<version>1.2.1.RELEASE</version>
</dependency>
spring-mvc.xml配置
<!--tomcat集群配置信息-->
<bean name="redisHttpSessionConfiguration" class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
<!--maxInactiveIntervalInSeconds 以秒为单位-->
<property name="maxInactiveIntervalInSeconds" value="10"/>
</bean>
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="100" />
<property name="maxIdle" value="10" />
</bean>
<bean id="jedisConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" destroy-method="destroy">
<property name="hostName" value="localhost"/>
<property name="port" value="9763"/>
<property name="timeout" value="3000"/>
<property name="usePool" value="true"/>
<property name="poolConfig" ref="jedisPoolConfig"/>
</bean>
增加redis集群配置方式
把以下内容配置到jedisConnectionFactory节点中去, 屏蔽单一节点配置方式
<!--集群配置-->
<!--<constructor-arg ref="redisClusterConfiguration" />-->
<!--集群使用-->
<bean id="redisClusterConfiguration"
class="org.springframework.data.redis.connection.RedisClusterConfiguration">
<property name="maxRedirects" value="3"></property>
<!-- 节点配置 -->
<property name="clusterNodes">
<set>
<!--<bean class="org.springframework.data.redis.connection.RedisClusterNode">-->
<!--<constructor-arg name="host" value="10.45.59.201"></constructor-arg>-->
<!--<constructor-arg name="port" value="7670"></constructor-arg>-->
<!--</bean>-->
<bean class="org.springframework.data.redis.connection.RedisClusterNode">
<constructor-arg name="host" value="10.45.59.202"></constructor-arg>
<constructor-arg name="port" value="7670"></constructor-arg>
</bean>
</set>
</property>
</bean>
web.xml添加拦截器
<filter>
<filter-name>springSessionRepositoryFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSessionRepositoryFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>