【问题标题】:Spring session with in memory store内存存储中的春季会话
【发布时间】:2019-01-18 07:40:07
【问题描述】:

为什么 spring.session.store-type 没有 in memory 选项。 ?

有什么方法可以在不编写我的 store 实现的情况下使用带有 in memory 选项的 spring session 吗?

我想使用 spring session 来获取带有令牌的 rest api

 @Bean
  public HttpSessionIdResolver httpSessionIdResolver() {
    return HeaderHttpSessionIdResolver.xAuthToken();
  }

【问题讨论】:

    标签: spring spring-session


    【解决方案1】:

    我找到了解决方案,有一个可以接受地图的 MapSessionRepository。 这是一个文档EnableSpringHttpSession

    @EnableSpringHttpSession
    @Configuration
    public class SpringHttpSessionConfig {
        @Bean
        public MapSessionRepository sessionRepository() {
            return new MapSessionRepository(new ConcurrentHashMap<>());
        }
    }
    

    【讨论】:

    • 这太棒了!我们将 spring-session 与 redis 一起使用,但不用于本地测试,因此使用了 catalina.session.StandardSession。使用您的代码,我可以使用 HttpSession 而不需要 redis 并且它更适合测试。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-22
    • 1970-01-01
    • 1970-01-01
    • 2015-10-19
    • 2013-11-29
    • 2012-02-17
    相关资源
    最近更新 更多