How to start Embedded Gemfire Application with SpringBoot

Gemfire is a memory caching solution for scaling software system, JavaSampleApproach will guide you how to create an Embedded Gemfire Application with SpringBoot.

Related article:
Infinispan Cache Solution | Spring Cache | Spring Boot
How to create a SpringBoot Gemfire RestfulApi

I. Technologies

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

II. Overview
1. Project Structure

embedded gemfire application

2. Step to do

– Create Spring Boot project
– Add needed dependencies
– Create a Gemfire Region Model
– Config Gemfire in Local model
– Implement Gemfire Repository
– Implement client for check Gemfire’s working
– Run SpringBoot project and result

III. Practices
1. Create Spring Boot project

Open Spring Tool Suite, on Menu bar, choose: File->New->Spring Starter Project, input needed project’s info:
embedded gemfire application project info

Press: Next then Finish, Spring boot project will be created

2. Add needed dependencies

– Add gemfire & spring-shell dependencies:

3. Create a Gemfire Region Model

@Region: Annotation to define the region an entity will be stored in.

4. Config Gemfire in Local model

Config Gemfire cache via @Bean: CacheFactoryBean gemfireCache()
Config Gemfire Region via @Bean: LocalRegionFactoryBean customerRegion(final GemFireCache cache)

In a main class of Spring Boot, use @EnableGemfireRepositories for enable Gemfire Caching.

5. Implement Gemfire Repository

Spring Data provides an interface: CrudRepository extends Repository for implementation a repository to retrieve entities from Gemfire caching:

Above sourcecode, we defines 4 methods to search gemfire entities base on: firstname, lastname and age.

6. Implement client for check Gemfire’s working

For a sample client, in main class, we implements CommandLineRunner for saving some customer entities then retrieving them.

7. Run SpringBoot project and result

Gemfire Logs:

Result:

IV. Sourcecode

SpringBootGemfire

By JavaSampleApproach | December 25, 2016.


Related Posts


Got Something To Say:

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

*