Spring Session原理如何深入解析?
- 内容介绍
- 文章标签
- 相关推荐
本文共计1787个文字,预计阅读时间需要8分钟。
在配置文件中,启用Redis作为HttpSession存储,并添加Session过滤器:
java场景一:需要启用RedisHttpSession@EnableRedisHttpSession导入RedisHttpSessionConfiguration.class
场景二:配置RedisHttpSessionRedisHttpSessionConfiguration 继承自SpringHttpSessionConfiguration,并添加了SessionRepositoryFilter(session过滤器)
SessionRepo
前景提要@EnableRedisHttpSession导入RedisHttpSessionConfiguration.class
Ⅰ、被RedisHttpSessionConfiguration继承的SpringHttpSessionConfiguration中添加了SessionRepositoryFilter(session过滤器);
Ⅱ、SessionRepositoryFilter创建时自动获取到SessionRepository;
Ⅲ、SessionRepositoryFilter的doFilterInternal方法把原生的request和response被包装成wrappedRequest和wrappedResponse,以后获取session将不再通过原生的request.session()方法而是通过wrappedRequest.getsession(),wrappedRequest.getsession()方法,wrappedRequest.getsession()的session是从SessionRepository获取得到的,做到从redis获取session。
本文共计1787个文字,预计阅读时间需要8分钟。
在配置文件中,启用Redis作为HttpSession存储,并添加Session过滤器:
java场景一:需要启用RedisHttpSession@EnableRedisHttpSession导入RedisHttpSessionConfiguration.class
场景二:配置RedisHttpSessionRedisHttpSessionConfiguration 继承自SpringHttpSessionConfiguration,并添加了SessionRepositoryFilter(session过滤器)
SessionRepo
前景提要@EnableRedisHttpSession导入RedisHttpSessionConfiguration.class
Ⅰ、被RedisHttpSessionConfiguration继承的SpringHttpSessionConfiguration中添加了SessionRepositoryFilter(session过滤器);
Ⅱ、SessionRepositoryFilter创建时自动获取到SessionRepository;
Ⅲ、SessionRepositoryFilter的doFilterInternal方法把原生的request和response被包装成wrappedRequest和wrappedResponse,以后获取session将不再通过原生的request.session()方法而是通过wrappedRequest.getsession(),wrappedRequest.getsession()方法,wrappedRequest.getsession()的session是从SessionRepository获取得到的,做到从redis获取session。

