-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
When using Spring Boot 3.5.x (Spring Data MongoDB 4.6.x) with Java 21 and reactive MongoDB, reactive queries such as mongoOperations.find(query, Message.class) fail with a CodeGenerationException caused by CGLIB attempting to subclass lambda-generated classes in Reactor.
This happens even if:
Entities are simple POJOs
Auditing annotations (@createdby, @LastModifiedDate) are removed
Mapping to raw Document.class is attempted
The pipeline is a simple Flux → DTO mapping
The issue appears to be inside Spring’s reactive entity instantiation / reactive pipeline instrumentation, not the user entity.
Steps to Reproduce:
Java 21
Spring Boot 3.5.6 (Spring Data MongoDB 4.6.x)
Reactive MongoDB configuration
Define entity:
@DaTa
@NoArgsConstructor
@AllArgsConstructor
@document(collection = "i18n_messages")
public class Message {
private String language;
private String description;
private List messages;
}
@DaTa
@NoArgsConstructor
@AllArgsConstructor
public class MessageItem {
private String messageCode;
private String display;
}
Call a reactive query:
Flux messages = mongoOperations.find(new Query(), Message.class);
messages.subscribe(System.out::println)
Expected behavior:
Flux emits mapped entities without exception.
Actual behavior:
Application fails with:
java.lang.IllegalStateException:
org.springframework.cglib.core.CodeGenerationException:
java.lang.NoClassDefFoundError-->IllegalName: reactor.core.publisher.Operators$LiftFunction$$Lambda/0x00000165e681fcd8_Accessor_99oe3o
Occurs even when mapping to Document.class and manually converting to DTO.
Works on Spring Boot 3.4.4 / Java 21.
Environment:
Java 21
Spring Boot 3.5.6
Spring Data MongoDB 4.6.3
ReactiveMongoOperations
Maven or Gradle build
No DevTools
Workarounds Tested:
Removing all auditing annotations (@createdby, @LastModifiedDate) — does not fix
Mapping raw Document → DTO manually — does not fix
Setting spring.mongodb.instantiator.simple=true — does not fix
Downgrading to Spring Boot 3.4.4 — works