AOT Processing Fails with NoClassDefFoundError for Apache HttpClient 4.x Classes
Environment
- Spring Boot: 4.0.0
- Spring Data Elasticsearch: (version bundled with Spring Boot 4.0.0)
- Java: 25.0.1
- Build Tool: Gradle
Description
When upgrading to Spring Boot 4.0.0 and running AOT processing (processAot task), the build fails with NoClassDefFoundError for Apache HttpClient 4.x classes.
Stack Trace
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/impl/auth/BasicScheme
at org.springframework.data.elasticsearch.client.elc.aot.ElasticsearchClientRuntimeHints.registerHints(ElasticsearchClientRuntimeHints.java:46)
at org.springframework.context.aot.RuntimeHintsBeanFactoryInitializationAotProcessor$RuntimeHintsRegistrarContribution.lambda$applyTo$0(RuntimeHintsBeanFactoryInitializationAotProcessor.java:117)
at java.base/java.util.LinkedHashMap$LinkedValues.forEach(LinkedHashMap.java:834)
at org.springframework.context.aot.RuntimeHintsBeanFactoryInitializationAotProcessor$RuntimeHintsRegistrarContribution.applyTo(RuntimeHintsBeanFactoryInitializationAotProcessor.java:111)
at org.springframework.context.aot.BeanFactoryInitializationAotContributions.applyTo(BeanFactoryInitializationAotContributions.java:94)
at org.springframework.context.aot.ApplicationContextAotGenerator.lambda$processAheadOfTime$0(ApplicationContextAotGenerator.java:59)
at org.springframework.context.aot.ApplicationContextAotGenerator.withCglibClassHandler(ApplicationContextAotGenerator.java:68)
at org.springframework.context.aot.ApplicationContextAotGenerator.processAheadOfTime(ApplicationContextAotGenerator.java:54)
at org.springframework.context.aot.ContextAotProcessor.performAotProcessing(ContextAotProcessor.java:107)
at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:84)
at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:49)
at org.springframework.context.aot.AbstractAotProcessor.process(AbstractAotProcessor.java:84)
at org.springframework.boot.SpringApplicationAotProcessor.main(SpringApplicationAotProcessor.java:96)
Caused by: java.lang.ClassNotFoundException: org.apache.http.impl.auth.BasicScheme
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:580)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:490)
... 13 more
Root Cause
The issue originates from ElasticsearchClientRuntimeHints.java at line 46, which attempts to register Apache HttpClient 4.x classes for serialization:
hints.serialization()
.registerType(org.apache.http.impl.auth.BasicScheme.class)
.registerType(org.apache.http.impl.auth.RFC2617Scheme.class)
.registerType(java.util.HashMap.class);
However, Elasticsearch Java Client 8.x has migrated from Apache HttpClient 4.x to HttpClient 5.x, which uses different package names:
- Old (HttpClient 4.x): org.apache.http.*
- New (HttpClient 5.x): org.apache.hc.client5.* and org.apache.hc.core5.*
Gradle Dependencies
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-elasticsearch")
// ... other dependencies
}
Expected Behavior
AOT processing should complete successfully without requiring Apache HttpClient 4.x classes.
Actual Behavior
AOT processing fails with NoClassDefFoundError because the referenced classes no longer exist in the classpath.