Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Running and Testing Hazelcast in a Spring Boot Application

DZone's Guide to

Running and Testing Hazelcast in a Spring Boot Application

How to start a Hazelcast instance in a Spring Boot application.

· Big Data Zone
Free Resource

Need to build an application around your data? Learn more about dataflow programming for rapid development and greater creativity. 

The folks over at OpenCredo recently published a blog post entitled, "Running and Testing Hazelcast in a Spring Boot Application." In the 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. Here's how to start a Hazelcast instance in a Spring Boot application. 

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

…
<parent>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-parent</artifactId>
 <version>1.3.0.RELEASE</version>
 <relativePath/>
</parent>
 …
<dependency>
 <groupId>com.hazelcast</groupId>
 <artifactId>hazelcast</artifactId>
 <!-- Version is managed by Spring Boot starter -->
</dependency>
…

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. com.hazelcast.config.Config bean.

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

Check out the Exaptive data application Studio. Technology agnostic. No glue code. Use what you know and rely on the community for what you don't. Try the community version.

Topics:
spring architecture ,spring ,spring boot

Published at DZone with permission of Peter Veentjer, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}