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
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。