spring-session web.xml配置
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/spring.xml,classpath:spring/dubbo-client.xml</param-value>
</context-param>
<!--
這個要配置在所有的過濾器之前
-->
<filter>
<filter-name>springSessionRepositoryFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>springSessionRepositoryFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
spring.xml配置
<!--設置頭 -->
<bean id="httpSessionStrategy" class="org.springframework.session.web.http.HeaderHttpSessionStrategy">
<!--
可設置自定義頭
<property name="headerName" value="${access_token}"></property>
-->
</bean>
<!-- springSession集成redis -->
<bean
class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
<!-- 設置過期時間 -->
<property name="maxInactiveIntervalInSeconds" value="1800" />
<!--<property name="httpSessionStrategy" ref="httpSessionStrategy"/>-->
</bean>
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="${redis.pool.maxActive}" />
<property name="maxIdle" value="${redis.pool.maxIdle}" />
<property name="maxWaitMillis" value="${redis.pool.maxWait}" />
<property name="testOnBorrow" value="true" />
</bean>
<bean id="redisConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="${redis.host}" />
<property name="port" value="${redis.port}" />
<property name="usePool" value="true" />
<property name="database" value="${redis.db}"></property>
<!-- <property name="poolConfig" ref="jedisPoolConfig" />
<property name="sentinelConfig" ref="sentinelConfiguration"/> -->
<!--哨兵不是必須-->
<constructor-arg name="sentinelConfig" ref="sentinelConfiguration"/>
<constructor-arg name="poolConfig" ref="jedisPoolConfig"></constructor-arg>
</bean>
源碼:
https://github.com/ln0491/spring-session-demo
最后編輯于 :
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者