Spring Integration
Connects the mapping, collection naming, and reactive lifecycle of ReactiveMongoTemplate to the MongoExecutionContext adapter without pulling in Spring Data MongoDB as a core dependency.
Spring Data MongoDB is maintained by the application.
build.gradle
textThe core library does not directly depend on Spring Data MongoDB. To use the ReactiveMongoTemplate configuration from an existing Spring application, the MongoExecutionContext adapter is provided at the application layer.
SpringReactiveMongoExecutionContext adapter
SpringReactiveMongoExecutionContext.java
javaIn the actual implementation, add the necessary Spring/MongoDB imports to the above class. The key is to connect entity read/write to MongoConverter, collection names to ReactiveMongoTemplate, and session initiation to the corresponding MongoClient.
Resolver and DSL Bean registration
MongoTemplateNameResolver.java
javaReactiveMongoDslConfiguration.java
javaScope connected in the adapter
@Document / collection name
Use ReactiveMongoTemplate#getCollectionName(...).
@Id / @Field / custom conversions
Use MongoConverter for entity ↔ Document conversion.
Reactive auditing
Connecting beforePersist(...) to ReactiveBeforeConvertCallback applies reactive auditing callbacks in the save() chain.
ReactiveAfterSaveCallback
Can be called in afterPersist(...) after a successful write.
Spring QueryMapper
Not applicable. DSL String field paths are based on actual MongoDB document field names.
Spring DataAccessException
Does not perform automatic conversion. The actual operation is performed by the Reactive Streams Driver.
When using @Field
Spring mapping is applied for entity save/retrieve conversion, but the String path of DSL conditions does not go through Spring QueryMapper. However, the exact id path segment is normalized to _id according to DSL rules.