Reactive find() with entity mapping fails on Java 21 / Spring Boot 3.5.x due to CGLIB CodeGenerationException
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<Document> → 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<MessageItem> messages; }
@Data @NoArgsConstructor @AllArgsConstructor public class MessageItem { private String messageCode; private String display; } Call a reactive query: Flux<Message> messages = mongoOperations.find(new Query(), Message.class); messages.subscribe(System.out::println)
Expected behavior:
Flux<Message> 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
Thank you for getting in touch - If you'd like us to spend some time investigating, please take the time to provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem.
public record GridResults<T>(List<T> content, long totalElements, int pageNumber, int pageSize) { }
@Override public Mono<GridResults<E>> seekList(final int page, final int size) { Pageable pageable = getDefaultPageable(page, size);
Query query = new Query().addCriteria(defaultFilter()).with(pageable);
//Get total count (for pagination info)
Mono<Long> count = mongoOperations.count(new Query().addCriteria(tenantFilter()), getEntityClass());
//Get page content
**Flux<E> contentFlux = mongoOperations.find(query, getEntityClass());**
//Combine count + content into Grid Results with exception handling
return contentFlux.collectList()
.zipWith(count)
.map(tuple -> new GridResults<>(
tuple.getT1(), // list of records
tuple.getT2(), // total count
page,
size
))
.flatMap(pageResult ->
{
if (pageResult.content().isEmpty()) {
return Mono.error(new NoDataFoundException());
}
return Mono.just(pageResult);
});
}
May I close this ticket or is there anything else I can assist you with? Without a runnable reproducer we're not willing to invest any further time.
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.