redis 处理session共享

2 篇文章 0 订阅
redis 安装
http://www.runoob.com/redis/redis-install.html


redis 参考
http://www.cnblogs.com/andyfengzp/p/6434287.html

http://dorole.com/1422/

http://blog.csdn.net/hdf734839030/article/details/52293275

1.pom.xml修改
增加
<!-- session redis依赖  start-->
<dependency>
 <groupId>org.springframework.session</groupId>
 <artifactId>spring-session-data-redis</artifactId>
 <version>1.3.0.RELEASE</version>
</dependency>
<dependency>
 <groupId>redis.clients</groupId>
 <artifactId>jedis</artifactId>
 <version>2.9.0</version>
</dependency>
<!-- session redis依赖  end -->


2.web.xml修改
在xml的前部位置(其他listner之前,加载配置文件之后)增加
    <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>




3.jdbc.properties修改
增加
redis.hostname=127.0.0.1
redis.port=6379
redis.pwd=123456


4.spring-hibernate.xml修改
增加
<!-- redis的配置 -->
<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.hostname}"/>
   <property name="port" value="${redis.port}"/>
   <property name="password" value="${redis.pwd}" />
   <property name="timeout" value="3000"/>
   <property name="usePool" value="true"/>
   <property name="poolConfig" ref="jedisPoolConfig"/>
</bean>

<!-- 为不同项目设置不同的cookie键值,避免产生host:端口部署不同项目产生覆盖cookie的问题 -->
<bean id="cookieSerializer" class="org.springframework.session.web.http.DefaultCookieSerializer" >
<property name="cookieName" value="修改成自己的项目名-cookie"></property>
</bean>
<bean id="redisHttpSessionConfiguration"
      class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
    <property name="maxInactiveIntervalInSeconds" value="1800"/>
    <property name="redisNamespace" value="修改成自己的项目名"></property>
    <property name="cookieSerializer" ref="cookieSerializer"></property>
</bean>


5.security.xml修改(如果不存在,这一步可以省略)
<bean id="sessionRegistry"
class="org.springframework.security.core.session.SessionRegistryImpl" />


修改为
<bean id="sessionRegistry" class="org.springframework.session.security.SpringSessionBackedSessionRegistry">
<constructor-arg name="sessionRepository" ref="sessionRepository"></constructor-arg>
</bean>


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值