使用Redis保存Spring session(基于XML配置文件)
2016-05-24 10:16
337 查看
Spring session是一种分布式session共享方案,提供了管理用户session信息的接口及实现。下文描述如何通过XML配置文件的方式实现使用Redis保存Spring session。
前置条件:Redis server已安装就绪。
(1) pom.xml配置(下载依赖包)
(4) web.xml配置(filter配置)
参考资料
1. http://docs.spring.io/spring-session/docs/current/reference/html5/
2. http://blog.csdn.net/zdsdiablo/article/details/50428212
3. http://www.itnose.net/detail/6272910.html
4. http://www.cnblogs.com/tankaixiong/p/3660075.html
5. http://jingyan.baidu.com/article/c33e3f488a1024ea15cbb5e3.html
前置条件:Redis server已安装就绪。
(1) pom.xml配置(下载依赖包)
... <dependencies> ... <dependency> <groupId>org.springframework.session</groupId> <artifactId>spring-session-data-redis</artifactId> <version>1.2.0.RELEASE</version> </dependency> ... </dependencies> ... <repositories> ... <repository> <id>spring-snapshot</id> <url>https://repo.spring.io/libs-snapshot</url> </repository> ... </repositories> ...(2) application.properties配置(保存redis server信息及redis连接池参数)
#redis config redis.host=192.168.1.100 redis.port=6379 redis.pass=lWnxl2SbwOS0QXEMi05d1fvK1aBevtRF redis.db=0 redis.maxIdle=300 redis.maxActive=600 redis.maxWait=1000 redis.testOnBorrow=true(3) applicationContext.xml配置(bean配置)
<!-- 属性文件位置 --> <context:property-placeholder location="classpath:application.properties" /> ... <context:annotation-config/> <bean class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration"/> <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig"> <property name="maxIdle" value="${redis.maxIdle}" /> <property name="maxTotal" value="${redis.maxActive}" /> <property name="maxWaitMillis" value="${redis.maxWait}" /> <property name="testOnBorrow" value="${redis.testOnBorrow}" /> </bean> <bean class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:host-name="${redis.host}" p:port="${redis.port}" p:password="${redis.pass}" p:database="${redis.db}" p:pool-config-ref="poolConfig"/>
(4) web.xml配置(filter配置)
<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. http://docs.spring.io/spring-session/docs/current/reference/html5/
2. http://blog.csdn.net/zdsdiablo/article/details/50428212
3. http://www.itnose.net/detail/6272910.html
4. http://www.cnblogs.com/tankaixiong/p/3660075.html
5. http://jingyan.baidu.com/article/c33e3f488a1024ea15cbb5e3.html
相关文章推荐
- redis安装问题小结
- 一个jar包里的网站
- 一个jar包里的网站之文件上传
- 一个jar包里的网站之返回对媒体类型
- Spring和ThreadLocal
- Spring Boot 开发微服务
- kindeditor 批量上传 上传失败 thinkphp swfupload session
- Spring整合Quartz(JobDetailBean方式)
- Spring整合Quartz(JobDetailBean方式)
- 使用 Redis 和 Python 构建一个共享单车的应用程序
- Redis偶发连接失败案例实战记录
- 杰奇登录后的东西都是在session里面的
- Redis中实现查找某个值的范围
- win 7 安装redis服务【笔记】
- redis的hGetAll函数的性能问题(记Redis那坑人的HGETALL)
- Redis和Memcached的区别详解
- 分割超大Redis数据库例子
- Redis总结笔记(一):安装和常用命令