天天看點

使用Spring Session和Redis管理session

  1. 使用Spring Boot以及Gradle建構項目
  2. 加入依賴

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

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

  3. 使用注解 @EnableRedisHttpSession
  4. 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.store-type=redis      
@RequestMapping("/")
@ResponseBody
String home(HttpSession session) {
    session.setAttribute("test", new Date());
    return "Hello World!";
}      
  • 1

繼續閱讀