通过第三方登录接口验证通过后返回登录信息,我将登录信息的用户 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 配置了
还需要做什么 不太懂。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
如果你的
redis安装正确,spring的部分也按照配置完成了,那你运行下试试,理论上不需要再做什么额外的东西了。你原先的代码,类似:
不需要有任何变动,因为
The Spring configuration is responsible for creating a Servlet Filter that replaces the HttpSession implementation with an implementation backed by Spring Session,所以,面向接口编程真的好灵活,有木有!^^直接在启动类上加入@EnableRedisHttpSession注解即可,引用一段spring boot官方文档的内容,
建议在web容器上做配置~
1.jetty-session-redis
2.https://github.com/jcoleman/tomcat-redis-session-manager