Spring Session实现Session管理的原理与详细配置

原理请参考这篇文章很详细:点击查看

以下是我的在开发中使用配置

如果是maven工程,加入如下依赖:

                <!-- spring-session -->
		<dependency>
		  <groupId>org.springframework.session</groupId>
		  <artifactId>spring-session-data-redis</artifactId>
		  <version>1.2.1.RELEASE</version>
		</dependency>
		<!-- jedis -->
		<dependency>
		  <groupId>redis.clients</groupId>
		  <artifactId>jedis</artifactId>
		  <version>2.8.1</version>
		</dependency>


在spring的配置文件中加入如下:

    <bean id="redisHttpSessionConfiguration"
	      class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
	    <property name="maxInactiveIntervalInSeconds" value="600"/>
	</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="redis服务地址"/>
	    <property name="port" value="6379"/>
	    <property name="password" value="密码" />
	    <property name="timeout" value="3000"/>
	    <property name="usePool" value="true"/>
	    <property name="poolConfig" ref="jedisPoolConfig"/>
	</bean>
然后在web.xml文件中加入他的拦截器:

	<!-- 加载spring容器 -->
 	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:context.xml</param-value>
	</context-param>
	<listener>
  		<listener-class>
  			 org.springframework.web.context.ContextLoaderListener
  		</listener-class>
 	</listener>
 	
	<!-- 配置spring-session拦截器 -->
        <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>



  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值