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:

2. Create a Java Model class

– Create a simple Java model:

3. Config Gemfire storage

Config CacheFactoryBean and LocalRegionFactoryBean

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.

In main class, enable GemfireRepositories by
@EnableGemfireRepositories

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

GemfireRestAPI


Related Posts



Got Something To Say:

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

*