Running and Testing Hazelcast in a Spring Boot Application

OpenCredo LogoThe folks over at OpenCredo recently published a blog post entitled, “Running and Testing Hazelcast in a Spring Boot Application“. In theyย post, theyย introduce some of the basic features of Hazelcast, some of its limitations, how to embed it in a Spring Boot application and write integration testings.


Hazelcast in a Spring Boot Application

Starting a Hazelcast instance in a Spring Boot application is easy:

  1. Include theย com.hazelcast:hazelcast dependency
  2. Initialise a com.hazelcast.config.Config Spring bean

The following example uses Spring Boot 1.3.0. This provides Hazelcast 3.5.3 as managed dependency.

pom.xml

โ€ฆ

 org.springframework.boot
 spring-boot-starter-parent
 1.3.0.RELEASE
 

 โ€ฆ

 com.hazelcast
 hazelcast
 

โ€ฆ

Configuration

@Configuration
public class HazelcastConfiguration {
ย @Bean
ย public Config config() {
ย ย ย return new Config(); // Set up any non-default config here
ย }
}

Spring Boot automatically start a Hazelcast instance when it finds both:

  1. Hazelcast in classpath
  2. A com.hazelcast.config.Configย bean.

On startup, anย instanceย ofย com.hazelcast.core.HazelcastInstanceย is then addedย toย the Spring Application Context.


Read they entireย post at OpenCredo ยป