I am using Apache Geode to develop a simple CRUD application. I've used below to start the Gemfire
docker run -it apachegeode/geode
Error:
java.lang.NoClassDefFoundError: org/springframework/data/gemfire/util/SpringExtensions
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at org.springframework.geode.boot.autoconfigure.RegionTemplateAutoConfiguration.lambda$setAutoConfiguredRegionTemplateDependencies$3(RegionTemplateAutoConfiguration.java:215)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1620)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
at org.springframework.geode.boot.autoconfigure.RegionTemplateAutoConfiguration.setAutoConfiguredRegionTemplateDependencies(RegionTemplateAutoConfiguration.java:215)
at org.springframework.geode.boot.autoconfigure.RegionTemplateAutoConfiguration.lambda$regionTemplateBeanFactoryPostProcessor$0(RegionTemplateAutoConfiguration.java:144)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:325)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:198)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:746)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)
at com.example.gemfirebasic.Application.main(Application.java:19)
Caused by: java.lang.ClassNotFoundException: org.springframework.data.gemfire.util.SpringExtensions
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 31 common frames omitted
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>00-gemfire-basic</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>00-gemfire-basic</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
<spring-geode.version>1.7.5</spring-geode.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.geode</groupId>
<artifactId>spring-geode-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.geode</groupId>
<artifactId>spring-geode-starter-session</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.geode</groupId>
<artifactId>spring-geode-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.geode</groupId>
<artifactId>spring-geode-starter-logging</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.geode</groupId>
<artifactId>spring-geode-bom</artifactId>
<version>${spring-geode.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Customer.java
@Region("Customers")
@RequiredArgsConstructor(staticName = "create")
@NoArgsConstructor
@Data
public class Customer {
@Id
@NonNull
private Long id;
@NonNull
private String name;
}
CustomerRepository.java
public interface CustomerRepository extends CrudRepository<Customer, Long> {
Customer findByNameLike(String name);
}
MainApp.java
@SpringBootApplication
@EnableEntityDefinedRegions(basePackageClasses = Customer.class, clientRegionShortcut = ClientRegionShortcut.LOCAL)
public class Application implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Autowired
private CustomerRepository customerRepository;
@Override
public void run(String... args) throws Exception {
Customer c1 = Customer.create(1L, "John Doe");
Customer c2 = Customer.create(2L, "Jane Doe");
Customer c3 = Customer.create(3L, "Jack Doe");
Customer c4 = Customer.create(4L, "Mike Doe");
Customer c5 = Customer.create(5L, "Matt Doe");
customerRepository.saveAll(Arrays.asList(c1, c2, c3, c4, c5));
customerRepository.findAll().forEach(System.out::println);
}
}
Looking at the dependencies for the 1.7.5 version of Spring Data for Geode it requires at least Spring Boot 2.7.5. You are using Spring Boot 2.7.1 which at the moment lead to pulling in different jars for Spring and Spring Boot I suspect leading to incompatible versions.
So to fix upgrade to the latest Spring Boot 2.7 version.