How to create a SpringBoot Gemfire RestfulApi

Spring Data REST provides a mechanics for creating and retrieving an Object from Gemfire storage.
In the article, JavaSampleApproach will introduce you how to create a Gemfire RestfulAPI.

Related Articles:
How to start Embedded Gemfire Application with SpringBoot
Infinispan Cache Solution | Spring Cache | Spring Boot

I. Technologies for SpringBoot Gemfire Restful Api

– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE

II. Overview

1. Project Structure

springboot gemfire restfulapi project structure

2. Step to do

– Create a Spring Boot project
– Create a Java Model class
– Config Gemfire storage
– Create a Gemfire repository
– Run & Check result

III. Practices

1. Create a Spring Boot project

Open Spring Tool Suite, on main menu, choose File->New->Spring Starter Project, input project info, press Next then Finish, spring boot project will be created successfully.

Gemfire & Restful dependencies:

Open pom.xml file, add needed dependencies:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""


	<description>Gemfire Rest API</description>

		<relativePath/> <!-- lookup parent from repository -->







2. Create a Java Model class

– Create a simple Java model:

package com.javasampleapproach.gemfirerestapi.model;

import java.util.concurrent.atomic.AtomicLong;

public class Customer {
	private static AtomicLong COUNTER = new AtomicLong(0L);
    private Long id;
    private String firstname;
    private String lastname;
    private int age;
	public Customer() { = COUNTER.incrementAndGet();
    public String getFirstname() {
        return firstname;
    public void setFirstname(String firstname) {
        this.firstname = firstname;
    public String getLastname() {
        return lastname;
    public void setLastname(String lastname) {
        this.lastname = lastname;
    public String toString(){
        return "firstname: " + firstname + " ,lastname: " + lastname + " ,age: " + age; 
    public int getAge() {
        return age;
    public void setAge(int age) {
        this.age = age;

3. Config Gemfire storage

Config CacheFactoryBean and LocalRegionFactoryBean

package com.javasampleapproach.gemfirerestapi.config;

import java.util.Properties;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.gemstone.gemfire.cache.GemFireCache;
import com.javasampleapproach.gemfirerestapi.model.Customer;

public class GemfireConfig {
    Properties gemfireProperties() {
        Properties gemfireProperties = new Properties();
        gemfireProperties.setProperty("name", "EmbeddedGemfireApplication");
        gemfireProperties.setProperty("mcast-port", "0");
        return gemfireProperties;
    CacheFactoryBean gemfireCache() {
        CacheFactoryBean gemfireCache = new CacheFactoryBean();
        return gemfireCache;
    LocalRegionFactoryBean customerRegion(final GemFireCache cache) {
        LocalRegionFactoryBean customerRegion = new LocalRegionFactoryBean<>();
        return customerRegion;

4. Create a Gemfire repository

Create a Gemfire repository interface by extends CrudRepository Spring interface.
@RepositoryRestResource is optional, it is used to redefine a default path.

package com.javasampleapproach.gemfirerestapi.repository;


import com.javasampleapproach.gemfirerestapi.model.Customer;

@RepositoryRestResource(collectionResourceRel = "customer", path = "customer")
public interface CustomerRepository extends CrudRepository {
	Customer findByFirstname(@Param("firstname") String firstname);
    Customer findByLastname(@Param("lastname") String lastname);
    Iterable findByAgeGreaterThan(@Param("age") int age);
    Iterable findByAgeLessThan(@Param("age") int age);

In main class, enable GemfireRepositories by

package com.javasampleapproach.gemfirerestapi;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

public class SpringBootGemfireRestfulApiApplication {

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

5. Run & Check result

Run project with Spring Boot Application mode.
Test time:

– Store 2 customers to Gemfire Caching:
springboot gemfire restfulapi - post entity

springboot gemfire restfulapi

– Retrieve all customers from Gemfire:
springboot gemfire restfulapi - get all

– Search RestfulAPI:
springboot  gemfire restfulapi search api

– Retrieve a customer from Gemfire:
 springboot gemfire restfulapi - get customer by id

– Find a customer by firstname:
springboot gemfire restfulapi - findbyfirstname

– Find a customer by lastname:
springboot gemfire restfulapi - findbylastname

– Find customers by age:
springboot gemfire restfulapi  - findbyagegreaterthan

springboot  gemfire restfulapi - findbyagelessthan

IV. Sourcecode


3 thoughts on “How to create a SpringBoot Gemfire RestfulApi”

  1. Good post.

    I have few queries here:
    1. How to view the saved data on UI like mysql, oracle, etc… ?
    2. How to deal with different tables/entities if they are having mappings ?
    3. How we can use this in Micro services architecture ?


  2. I have viewed that wise real estate agents all over the place are starting to warm up to FSBO Advertising and marketing. They are realizing that it’s more than merely placing a sign post in the front property. It’s really regarding building human relationships with these traders who sooner or later will become purchasers. So, whenever you give your time and effort to serving these suppliers go it alone — the “Law connected with Reciprocity” kicks in. Good blog post.

Leave a Reply

Your email address will not be published. Required fields are marked *