第 2 章 使用 Spring Session 进行外部化会话
将 Spring 应用程序的会话数据存储在 Data Grid 缓存中,并独立于容器。
2.1. 使用 Spring Session 进行外部化会话 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
使用 Spring Session API 将会话数据外部化到 Data Grid。
流程
在您的
pom.xml中添加依赖项。-
嵌入式缓存:
infinispan-spring5-embedded 远程缓存:
infinispan-spring5-remote以下示例用于远程缓存:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
-
嵌入式缓存:
指定适当的
FactoryBean来公开CacheManager实例。-
嵌入式缓存:
SpringEmbededCacheManagerFactoryBean -
远程缓存:
SpringRemoteCacheManagerFactoryBean
-
嵌入式缓存:
使用适当的注解启用 Spring Session。
-
嵌入式缓存
:@EnableInfinispanEmbeddedHttpSession 远程缓存
:@EnableInfinispanRemoteHttpSession这些注解具有可选参数:
-
maxInactiveIntervalInSeconds以秒为单位设置会话过期时间。默认值为1800。 -
cacheName指定存储会话的缓存名称。默认值为会话。
-
-
嵌入式缓存
以下示例显示了基于注解的完整配置: