Getting started with Spring and Hazelcast

This article is a getting-started tutorial on integrating Hazelcast into a Spring project.

Part 1: Create Spring project

If you have already created the Spring project, skip to Part 2.

  1. Create a maven project.
    mvn archetype:generate -DgroupId=spring_hazelcast -DartifactId=spring_hazelcast
  2. Add spring dependencies into pom.
    https://gist.github.com/2308457
  3. Create a TestBean.
    https://gist.github.com/2308466
  4. Create beans.xml in your source root (src/main/java/beans.xml)
    https://gist.github.com/2308478
  5. Test your Spring app.
    https://gist.github.com/2308514

If you see “success” printed, now we can integrate Hazelcast.

Part 2: Integrate Hazelcast

  1. Add Hazelcast dependencies
    https://gist.github.com/2308541
  2. Add hz name spaces, Hazelcast configuration and an Hazelcast map bean to beans xml.
    In hz:map definition, “id” is spring bean id, name refers to Hazelcast map’s name.
    https://gist.github.com/2308666
  3. Test Hazelcast.
    https://gist.github.com/2308679

You can download and browse the getting started project here:
https://github.com/enesakar/spring_hazelcast