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>
<!--
這個(gè)要配置在所有的過濾器之前
-->
<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配置
<!--設(shè)置頭 -->
<bean id="httpSessionStrategy" class="org.springframework.session.web.http.HeaderHttpSessionStrategy">
<!--
可設(shè)置自定義頭
<property name="headerName" value="${access_token}"></property>
-->
</bean>
<!-- springSession集成redis -->
<bean
class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
<!-- 設(shè)置過期時(shí)間 -->
<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
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。