gpt4 book ai didi

java - Spring session 碰撞 session

转载 作者:可可西里 更新时间:2023-11-01 11:24:31 25 4
gpt4 key购买 nike

在 spring session 中,我们有两个应用程序使用相同的 redis 服务器,结果有时我们会得到 ClassNotFoundException 无法序列化,因为一个应用程序试图序列化由另一个应用程序创建的 session 。不过,有时这两种服务都会开始出现此错误。

为了缓解这个问题,我们确定使用 redisNamespace。但是假设我们有 2 项服务并且只能更新一项服务。如果我们将 redisNamespace 添加到一个服务中,这两个服务上的 session 不会发生冲突吗?例如服务 A 的命名空间为“test”,而服务 B 的命名空间为默认的“”(服务 B 是否仍会尝试使用服务 A 的 session ?),或者我们是否也需要更改服务 B 的命名空间?

此外,我们无法一致地重现此问题,有时 ClassNotFoundException 不会出现,有时会出现,非常感谢任何一致地重现此问题的指南。

我们使用的spring版本也是1.3.1.RELEASE。

最佳答案

redisNamespace配置参数旨在为 session 提供特定于应用程序的命名空间,以支持多个应用程序使用相同的 Redis 实例来存储 session 的用例。来自 1.3.x reference manual :

redisNamespace - allows configuring an application specific namespace for the sessions. Redis keys and channel ids will start with the prefix of spring:session:<redisNamespace>:.

所以你的问题的答案是肯定的——如果一个应用程序没有配置特定的命名空间,但另一个使用相同 Redis 实例的应用程序配置了,它们将使用不同的命名空间,因此不会发生冲突。

作为旁注,redisNamespace 的语义在 Spring Session 2.0 中已更改,因此您现在可以使用此参数配置完整的命名空间,而不是像 Spring Session 1.3 中那样仅配置前缀的最后一部分。来自 2.0.x reference manual :

redisNamespace - allows configuring an application specific namespace for the sessions. Redis keys and channel IDs will start with the prefix of <redisNamespace>:.

关于java - Spring session 碰撞 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50956140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com