Chapter 3. Running in Server Mode


Store and retrieve data from remote Data Grid clusters using Hot Rod, a custom TCP binary wire protocol.

3.1. Setting Up the RemoteCacheManager

  1. Provide the location for the Data Grid server so the starter can create the RemoteCacheManager bean.

    The starter first tries to find the server location in hotrod-client.properties and then from application.properties.

  2. Use the Spring @Autowired annotation to include your own custom cache manager class in your application:

    private final RemoteCacheManager cacheManager;
    
    @Autowired
    public YourClassName(RemoteCacheManager cacheManager) {
        this.cacheManager = cacheManager;
    }
    Copy to Clipboard Toggle word wrap

Hot Rod client properties

Specify client configuration in hotrod-client.properties on your classpath, for example:

# List Infinispan or Data Grid servers by IP address or hostname at port 11222.
infinispan.client.hotrod.server_list=127.0.0.1:6667
Copy to Clipboard Toggle word wrap

For more information, see org.infinispan.client.hotrod.configuration.

Application properties

Configure your project with application.properties. See Application Properties for more information.

3.2. Configuring Marshalling

Configure Data Grid servers to use Java serialization to marshall objects.

By default Data Grid server uses a ProtoStream serialization library as the default marshaller. However, the ProtoStream marshaller is not supported for Spring integration. For this reason you should use the Java Serialization Marshaller.

  • Specify the following properties in your application.properties:

    infinispan.remote.marshaller=org.infinispan.commons.marshall.JavaSerializationMarshaller 
    1
    
    infinispan.remote.java-serial-whitelist=your_marshalled_beans_package.* 
    2
    Copy to Clipboard Toggle word wrap
1
Use the Java Serialization Marshaller.
2
Adds your classes to the serialization whitelist so Data Grid marshalls your objects. You can specify a comma-separated list of fully qualified class names or a regular expression to match classes.

3.3. Cache Manager Configuration Beans

Customize the cache manager with the following configuration beans:

  • InfinispanRemoteConfigurer
  • Configuration
  • InfinispanRemoteCacheCustomizer

    Note

    You can create one InfinispanRemoteConfigurer bean only. However you can create multiple configurations with the other beans.

InfinispanRemoteConfigurer Bean

@Bean
public InfinispanRemoteConfigurer infinispanRemoteConfigurer() {
    return () -> new ConfigurationBuilder()
        .addServer()
        .host("127.0.0.1")
        .port(12345)
        .build();
}
Copy to Clipboard Toggle word wrap

Configuration Bean

@Bean
public org.infinispan.client.hotrod.configuration.Configuration customConfiguration() {
    new ConfigurationBuilder()
        .addServer()
        .host("127.0.0.1")
        .port(12345)
        .build();
}
Copy to Clipboard Toggle word wrap

InfinispanRemoteCacheCustomizer Bean

@Bean
public InfinispanRemoteCacheCustomizer customizer() {
    return b -> b.tcpKeepAlive(false);
}
Copy to Clipboard Toggle word wrap

Tip

Use the @Ordered annotation to apply customizers in a specific order.

3.4. Enabling Spring Cache Support

Add the @EnableCaching annotation to your application to enable Spring Cache support.

When the Data Grid starter detects the RemoteCacheManager bean, it instantiates a new SpringRemoteCacheManager, which provides an implementation of Spring Cache.

3.5. Exposing Data Grid Statistics

Data Grid supports the Spring Boot Actuator to expose cache statistics as metrics.

To use the Actuator, add the following to your pom.xml file:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
  <version>${version.spring.boot}</version>
 </dependency>

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
  <version>${version.spring.boot}</version>
</dependency>
Copy to Clipboard Toggle word wrap

You must then activate statistics for the appropriate cache instances, either programmatically or declaratively.

Programmatically

@Bean
public InfinispanCacheConfigurer cacheConfigurer() {
  return cacheManager -> {
     final org.infinispan.configuration.cache.Configuration config =
           new ConfigurationBuilder()
                 .jmxStatistics().enable()
                 .build();

     cacheManager.defineConfiguration("my-cache", config);
  };
}
Copy to Clipboard Toggle word wrap

Declaratively

<local-cache name="my-cache" statistics="true"/>
Copy to Clipboard Toggle word wrap

The Spring Boot Actuator registry binds cache instances when your application starts. If you create caches dynamically, you should use the CacheMetricsRegistrar bean to bind caches to the Actuator registry, as follows:

@Autowire
CacheMetricsRegistrar cacheMetricsRegistrar;

@Autowire
CacheManager cacheManager;
...

cacheMetricsRegistrar.bindCacheToRegistry(cacheManager.getCache("my-cache"));
Copy to Clipboard Toggle word wrap
Back to top
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2026 Red Hat