您的位置:首页 > 数据库 > Redis

使用Spring Session和Redis管理session

2016-05-30 17:16 405 查看
使用Spring Boot以及Gradle构建项目

加入依赖

compile ‘org.springframework.session:spring-session:1.2.0.RELEASE’

compile ‘org.springframework.boot:spring-boot-starter-data-redis’

使用注解 @EnableRedisHttpSession

application.properties配置

加入redis配置:

spring.redis.database=0
spring.redis.host=localhost
spring.redis.password=
spring.redis.pool.max-active=8
spring.redis.pool.max-idle=8
spring.redis.pool.max-wait=-1
spring.redis.pool.min-idle=0
spring.redis.port=6379


加入spring session 配置:

spring.session.store-type=redis


最后进行测试

@RequestMapping("/")
@ResponseBody
String home(HttpSession session) {
session.setAttribute("test", new Date());
return "Hello World!";
}


还是原来使用session的方式,可以在redis中查看到一条记录。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring session redis