栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在Spring 4中如何进行基于关系数据库的HTTP会话持久性?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在Spring 4中如何进行基于关系数据库的HTTP会话持久性?

使用Spring Session(它会透明地覆盖Java
EE中的HttpSessions),您只需

SessionRepository
使用自定义ex即可实现接口并实现它。
JdbcSessionRepository
。这很容易做到。实现后,只需手动添加(不需要
@EnableRedisHttpSession
注释)创建的过滤器即可过滤链,例如波纹管:

@Configuration@EnableWebMvcSecuritypublic class SecurityConfiguration extends WebSecurityConfigurerAdapter {   //other stuff...   @Autowired   private SessionRepository<ExpiringSession> sessionRepository;   private HttpSessionStrategy httpSessionStrategy = new cookieHttpSessionStrategy(); // or HeaderHttpSessionStrategy   @Bean   public SessionRepository<ExpiringSession> sessionRepository() {       return new JdbcSessionRepository();   }   @Override   protected void configure(HttpSecurity http) throws Exception {       super.configure(http);       SessionRepositoryFilter<ExpiringSession> sessionRepositoryFilter = new SessionRepositoryFilter<>(sessionRepository);       sessionRepositoryFilter.setHttpSessionStrategy(httpSessionStrategy);       http .addFilterBefore(sessionRepositoryFilter, ChannelProcessingFilter.class);   }}

在这里,您可以看到

SessionRepository
界面的外观。它只有4种方法可以实现。有关如何创建Session对象的信息,可以查看
MapSessionRepository
MapSession
实现(或
RedisOperationsSessionRepository
RedisSession
)。

public interface SessionRepository<S extends Session> {   S createSession();   void save(S session);   S getSession(String id);   void delete(String id);}

示例解决方案https://github.com/Mati20041/spring-session-jpa-
repository



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/418866.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号