Create a Spring Boot Application for Hazelcast Cloud

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 Cloud dashboard for your cluster; clusterID is provided in the Cluster details, and the other credentials in the Advanced option under Connect Client.
    • clusterID

    • discoveryToken

    • keyStorePassword

    • trustStorePassword (same as keyStorePassword)

  4. Download the keystore and truststore files from the Cloud console and add them to the src/main/resources/ directory. You can find these files in the Cloud dashboard for your cluster under Connect Client > 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 HzCloudDemoApplication {

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

        name = "",
        havingValue = "true"
    ClientConfig hazelcastClientConfig(
        @Value("${}") String discoveryToken,
        @Value("${}") String clusterId,
        @Value("${}") Resource keyStore,
        @Value("${}") String keyStorePassword,
        @Value("${}") Resource trustStore,
        @Value("${}") 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 Cloud Standard 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 ten 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 Cloud Standard cluster.

Next Steps

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

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

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