Since Infinispan 9, Infinispan provides implementation for Spring Session.
Spring Session implementation for Infinispan.
API and implementations for managing a user’s session information.
Open Source In Memory Data Grid.
- Embedded Mode (a.k.a Library Mode)
- Client/Server Mode (Hot Rod Client)
- maxInactiveIntervalInSeconds - session timeout seconds (default: 1800 sec)
- sessionsCacheName - sessions store cache name (default: springSessions)
git clone & Maven build.
$ git clone https://github.com/kazuhira-r/spring-session-infinispan.git
$ cd spring-session-infinispan
$ mvn install -DskipTests=true
Add dependency, this module.
<dependency>
<groupId>org.littlewings</groupId>
<artifactId>spring-session-infinispan</artifactId>
<version>${spring.session.infinispan.version}</version>
</dependency>
Add dependency, Infinispan Core module.
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
<version>${infinispan.version}</version>
</dependency>
Enable, Spring Session Infinispan for Embedded Mode.
@SpringBootApplication
@EnableInfinispanEmbeddedHttpSession
public class App {
Write a Bean definition of EmbeddedCacheManager.
@Bean
public EmbeddedCacheManager embeddedCacheManager() {
EmbeddedCacheManager cacheManager =
new DefaultCacheManager(new GlobalConfigurationBuilder().transport().defaultTransport().build());
cacheManager
.defineConfiguration("springSessions",
new org.infinispan.configuration.cache.ConfigurationBuilder().clustering().cacheMode(CacheMode.DIST_SYNC).build());
return cacheManager;
}
Note: It's necessary to define Cache on the server side beforehand in case of Client/Server Mode.
Add depencency, Infinispan Client Hot Rod module.
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-client-hotrod</artifactId>
<version>${infinispan.version}</version>
</dependency>
Enable, Spring Session Infinispan for Client/Server Mode.
@SpringBootApplication
@EnableInfinispanRemoteHttpSession
public class App {
Write a Bean definition of RemoteCacheManager.
@Bean
public RemoteCacheManager remoteCacheManager() {
return new RemoteCacheManager(
new org.infinispan.client.hotrod.configuration.ConfigurationBuilder()
.addServers("localhost:11222")
.build());
}