spring-native
spring-native copied to clipboard
Mongo Change Streams Doesn't Work with v0.12.x
So, I'm working with Mongo change streams.
reactiveMongoTemplate.changeStream("Manga", FULL_DOC, Manga.class)
But I'm getting this error when I try to subscribe to events:
Error processing com.mongodb.reactivestreams.client.internal.MongoDatabaseImpl@414f8bf8 Exception is org.bson.codecs.configuration.CodecConfigurationException: Invalid @BsonCreator constructor in ChangeStreamDocument. Invalid Property type for 'operationType'. Expected class com.mongodb.client.model.changestream.OperationType, found class java.lang.String.
I have added the ChangeStreamDocument class to my reflection config, and It works fine when I'm not running on the binary.
Here is my repo: https://github.com/SentryMan/Manga-Spring-Backend/blob/8bd0c2367265fc4e7fedb67be2aecd9deb4e4816/src/main/java/com/mangasite/services/MangaService.java#L94-L95
Maybe you miss a type/reflection hint on com.mongodb.client.model.changestream.OperationType.
Yeah, this doesn't work https://github.com/SentryMan/Manga-Spring-Backend/commit/5d3ee9c8bc27286abefb89e5bedc900c44fac788
Also, I had it working before without needing to add reflection. I only recently noticed it had stopped working. I personally suspect that when this constructor got deprecated something broke.
@Deprecated
public ChangeStreamDocument(final OperationType operationType,
final BsonDocument resumeToken,
final BsonDocument namespaceDocument,
final BsonDocument destinationNamespaceDocument,
final TDocument fullDocument,
final BsonDocument documentKey,
final BsonTimestamp clusterTime,
final UpdateDescription updateDescription,
final BsonInt64 txnNumber,
final BsonDocument lsid)
Your repro is using an outdated RC, please use Spring Native 0.12.1 with latest Spring Boot 2.7.x version.
That was the first thing I tried. https://github.com/SentryMan/Manga-Spring-Backend/blob/a9931a7876e45f3c55694e8d698df2c14edfe6eb/pom.xml On the fix branch I was running 2.7.3 with 0.12.1
It seems when I revert the version to spring native 11.4 / 2.6.6 it works
Yeah, the problem seems to start at v0.12.0
Could be missing reflection hints on the parameters that are used to identify the new constructor reflectively. Please make a try with reflection hints for all the parameter types used in ChangeStreamDocument constructors.
That also didn't work
How shall we proceed?
I tried https://github.com/SentryMan/Manga-Spring-Backend/blob/a9931a7876e45f3c55694e8d698df2c14edfe6eb/pom.xml, but when running it with mvn spring-boot:build-image + docker run docker.io/library/manga-backend:3.0.0, I get a Could not resolve placeholder 'SECRET_KEY' in value "${SECRET_KEY}". So if you want some help from me, please provide a repro that works, some thing where for example Mongo and the native app runs via Docker Compose with the various environnement variable set.
I have created an example repo to show this error https://github.com/SentryMan/Spring-Native-Mongo-Change-Stream
Spring Native is now superseded by Spring Boot 3 official native support, see the related reference documentation for more details.
As a consequence, I am closing this issue, and recommend trying your use case with latest Spring Boot 3 version. If you still experience the issue reported here, please open an issue directly on the related Spring project (Spring Framework, Data, Security, Boot, Cloud, etc.) with a reproducer.
Thanks for your contribution on the experimental Spring Native project, we hope you will enjoy the official native support introduced by Spring Boot 3.