Spring SessionとRedisを使ってセッションを管理します.


  • Spring Boot及びGraadleを用いて構築されたプロジェクト
  • 加入依存comple‘org.springframe ebook.session:spring-session:1.2.0.RELEASE’comple‘org.springframe ew.book:spring-boot-starter-data-redis’
  • 使用注解@EnbaleRedisHttpSession
  • appication.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!";
    }
    
    やはり元々sessionを使う方式です.レコードはredisで確認できます.