This topic explains how to use Spring Data repositories with Spring Boot for VMware Tanzu GemFire.
Using Spring Data Repositories with VMware GemFire makes short work of data access operations when you use VMware GemFire as your System of Record (SoR) to persist your application’s state.
Spring Data Repositories provide a convenient and powerful way to define basic CRUD and simple query data access operations by specifying the contract of those data access operations in a Java interface.
Spring Boot for Tanzu GemFire auto-configures the Spring Data for VMware GemFire Repository extension when either is declared on your application’s classpath. You need not do anything special to enable it. You can start coding your application-specific Repository interfaces.
The following example defines a Customer
class to model customers and map it to the VMware GemFire Customers
Region by using the Spring Data for VMware GemFire @Region
mapping annotation:
Example 1. Customer
entity class
package example.app.crm.model;
@Region("Customers")
class Customer {
@Id
private Long id;
private String name;
}
The following example shows how to declare your Repository for Customers
:
Example 2. CustomerRepository
for persisting and accessing Customers
package example.app.crm.repo;
interface CustomerRepository extends CrudRepository<Customer, Long> {
List<Customer> findByLastNameLikeOrderByLastNameDescFirstNameAsc(String customerLastNameWildcard);
}
Then you can use the CustomerRepository
in an application service class:
Example 3. Inject and use the CustomerRepository
package example.app;
@SpringBootApplication
@EnableEntityDefinedRegions(basePackageClasses = Customer.class)
class SpringBootGemFireClientCacheApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootGemFireClientCacheApplication.class, args);
}
@Bean
ApplicationRunner runner(CustomerRepository customerRepository) {
return args -> {
// Matches Williams, Wilson, etc.
List<Customer> customers =
customerRepository.findByLastNameLikeOrderByLastNameDescFirstNameAsc("Wil%");
// process the list of matching customers...
};
}
}
For more detail, see Spring Data Commons’ Repositories abstraction and Spring Data for VMware GemFire’s Repositories extension.
Content feedback and comments