java 如何将内存中会话存储增加到最大值

gajydyqb  于 2023-01-11  发布在  Java
关注(0)|答案(1)|浏览(149)

请注意,这与并发用户会话无关,而是与可存储在内存中的会话总数有关。
以下是日志:

java.lang.IllegalStateException: Max sessions limit reached: 10000
    at org.springframework.web.server.session.InMemoryWebSessionStore$InMemoryWebSession.checkMaxSessionsLimit(InMemoryWebSessionStore.java:276)
    at org.springframework.web.server.session.InMemoryWebSessionStore$InMemoryWebSession.save(InMemoryWebSessionStore.java:251)
    at org.springframework.web.server.session.DefaultWebSessionManager.save(DefaultWebSessionManager.java:123)
    at org.springframework.web.server.session.DefaultWebSessionManager.lambda$null$0(DefaultWebSessionManager.java:88)
    at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:113)
    at reactor.core.publisher.FluxIterable$IterableSubscription.slowPath(FluxIterable.java:272)
    at reactor.core.publisher.FluxIterable$IterableSubscription.request(FluxIterable.java:230)
    at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.request(FluxMapFuseable.java:171)
    at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.onSubscribe(FluxConcatMap.java:236)

您可以在此处找到Spring文档https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/server/session/InMemoryWebSessionStore.html
我创建了一个如下所示的bean,但不确定:

@Bean
    public InMemoryWebSessionStore inMemoryWebSessionStore() {
        InMemoryWebSessionStore inMemoryWebSessionStore = new InMemoryWebSessionStore();
        inMemoryWebSessionStore.setMaxSessions(-1);
        return inMemoryWebSessionStore;
    }
5lhxktic

5lhxktic1#

我终于找到了一个对我有效的解决办法。

@Bean
public WebSessionManager webSessionManager () {
    DefaultWebSessionManager webSessionManager = new DefaultWebSessionManager();
    InMemoryWebSessionStore inMemoryWebSessionStore = new InMemoryWebSessionStore();
    inMemoryWebSessionStore.setMaxSessions(2147483647); //2147483647 - MAX_VALUE of Integer
    webSessionManager.setSessionStore(inMemoryWebSessionStore);
    return webSessionManager;
}

相关问题