Create a Spring Boot Application for Hazelcast Viridian

In this tutorial, you’ll learn how to create a basic Spring Boot application that connects to a cluster.


The Spring Framework is a Java framework for creating standalone applications that run on the Java Virtual Machine (JVM).

Spring Boot is a tool that makes it easier and faster to develop applications with the Spring Framework by providing many features, including autoconfiguration.

If you’re unfamiliar with Spring or Spring Boot, see the Spring Boot documentation.

Before you Begin

You need the following:

Step 1. Clone the Sample Project

All the code for this project is available on GitHub. In this step, you’ll clone the project and learn how it works.

  1. Clone the GitHub repository.

    • HTTPS

    • SSH

    git clone
    cd spring-boot-sample
    git clone
    cd spring-boot-sample
  2. Open the src/main/resources/ file.

  3. Add connection credentials for your cluster to the file. You can find these credentials in the Hazelcast Viridian console under Connect Your Application > Advanced Setup.

    • clusterName

    • discoveryToken

    • keyStorePassword

    • trustStorePassword (same as keyStorePassword)

  4. Download the keystore and truststore files from the Hazelcast Viridian console and add them to the src/main/resources/ directory. You can find these files in the Hazelcast Viridian console under Connect Your Application > Advanced Setup.


If the Hazelcast client is on the classpath and a suitable configuration is found, Spring Boot automatically configures a HazelcastInstance that you can inject into your application.


Spring Boot first attempts to create a Hazelcast client by checking the presence of a com.hazelcast.client.config.ClientConfig bean. This bean is configured using the information in the file.

public class HzViridianDemoApplication {

    public static void main(String[] args) {, args);

        name = "hazelcast.viridian.tlsEnabled",
        havingValue = "true"
    ClientConfig hazelcastClientConfig(
        @Value("${hazelcast.viridian.discoveryToken}") String discoveryToken,
        @Value("${hazelcast.viridian.clusterName}") String clusterName,
        @Value("${hazelcast.viridian.keyStore}") Resource keyStore,
        @Value("${hazelcast.viridian.keyStorePassword}") String keyStorePassword,
        @Value("${hazelcast.viridian.trustStore}") Resource trustStore,
        @Value("${hazelcast.viridian.trustStorePassword}") String trustStorePassword
    ) throws IOException {
        Properties props = new Properties();
        props.setProperty("", keyStore.getURI().getPath());
        props.setProperty("", keyStorePassword);
        props.setProperty("", trustStore.getURI().getPath());
        props.setProperty("", trustStorePassword);
        ClientConfig config = new ClientConfig();
        config.getNetworkConfig().setSSLConfig(new SSLConfig().setEnabled(true).setProperties(props));
        config.setProperty("", "");

        return config;


When the com.hazelcast.client.config.ClientConfig bean is present, a HazelcastInstance is injected into the application classes. This instance is a Hazelcast client with an established connection to the Viridian Serverless cluster.

public class MapService {

    private static final Logger logger = LoggerFactory.getLogger(MapService.class);

    private final HazelcastInstance hazelcastInstance;

    public MapService(HazelcastInstance hazelcastInstance) {
        this.hazelcastInstance = hazelcastInstance;

    public void onApplicationIsReady(ContextRefreshedEvent contextRefreshedEvent) {
        var mapName = "MyMap";
        Map<String, String> myMap = hazelcastInstance.getMap(mapName);
        for (int i = 0; i < 10; i++) {
            myMap.put(UUID.randomUUID().toString(), "Value-" + i);
        }"Map prepopulated [mapName={},size={}]", mapName, myMap.size());


Step 2. Connect the Client

In the spring-boot-sample/ directory, execute the following:

  • Linux and Mac

  • Windows

./mvnw spring-boot:run
mvnw.cmd spring-boot:run

The client connects to the cluster and adds 10 random entries to a map called MyMap.

Authenticated with server
Map prepopulated [mapName=MyMap,size=10]


In this tutorial, you learned how to set up a Spring Boot application to connect to a Viridian Serverless cluster.

Next Steps

Use this boilerplate application as a foundation to start building your own application.

See the Hazelcast Viridian documentation to continue learning or try another tutorial.

See the Spring Boot documentation for more about using Hazelcast with Spring.