java - spring boot 怎么把session 放到redis
ringa_lee
ringa_lee 2017-04-18 09:04:48
[Java讨论组]

通过第三方登录接口验证通过后返回登录信息,我将登录信息的用户 id 和 ticket 作为键和值存在 session 中

具体是这样子:

HttpSession session= request.getSession();
session.setAttribute(UserId,ticket);

现在想 将这个session 存到redis.

具体的准备差不多按照 http://docs.spring.io/spring-session/docs/current/reference/html5/guides/boot.html 配置了

还需要做什么 不太懂。

ringa_lee
ringa_lee

ringa_lee

全部回复(3)
迷茫

如果你的redis安装正确,spring的部分也按照配置完成了,那你运行下试试,理论上不需要再做什么额外的东西了。

你原先的代码,类似:

HttpSession session= request.getSession();
session.setAttribute(UserId,ticket);

不需要有任何变动,因为The Spring configuration is responsible for creating a Servlet Filter that replaces the HttpSession implementation with an implementation backed by Spring Session,所以,面向接口编程真的好灵活,有木有!^^

PHP中文网

直接在启动类上加入@EnableRedisHttpSession注解即可,引用一段spring boot官方文档的内容,

Spring Session provides support for managing a user’s session information. If you are writing a web application and Spring Session and Spring Data Redis are both on the classpath, Spring Boot will auto-configure Spring Session through its @EnableRedisHttpSession. Session data will be stored in Redis and the session timeout can be configured using the server.session.timeout property.

ringa_lee

建议在web容器上做配置~

1.jetty-session-redis
2.https://github.com/jcoleman/tomcat-redis-session-manager

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号