Parameter Styles
Typed handlers (@OnInsert, @OnUpdate, @OnDelete, @OnReplace) support three parameter styles. @OnChange supports only CONTEXT_ONLY.
| Style | Parameters | Notes |
|---|---|---|
CONTEXT_ONLY | (ChangeStreamContext<T> ctx) | Access metadata + document via ctx.getFullDocument(). |
DOCUMENT_ONLY | (T doc) | Receive the deserialized document directly. Requires a concrete documentType. |
DOCUMENT_AND_CONTEXT | (T doc, ChangeStreamContext<T> ctx) | Both the document and the context. Requires a concrete documentType. |
Return Types — Mode Exclusivity
The return type is bound to the configured execution mode (flowwarden.default-mode):
| Mode | Required return type | Other return types |
|---|---|---|
IMPERATIVE (default) | void | Mono<Void> is rejected at startup |
REACTIVE | Mono<Void> | void is rejected at startup |
CompletableFuture, Flux, String, etc. — are rejected at startup with unsupported return type.
Full Signature Matrix
- Imperative (void)
- Reactive (Mono)
| Style | Signature |
|---|---|
CONTEXT_ONLY | void handle(ChangeStreamContext<T> ctx) |
DOCUMENT_ONLY | void handle(T doc) |
DOCUMENT_AND_CONTEXT | void handle(T doc, ChangeStreamContext<T> ctx) |
@OnChange: only void handle(ChangeStreamContext<T> ctx) is allowed.Examples
CONTEXT_ONLY
DOCUMENT_ONLY
DOCUMENT_AND_CONTEXT
Reactive variants
Injecting Other Beans
Need aMongoTemplate, a custom service, or any other Spring bean? Inject it through the handler class (constructor or @Autowired field), not via the handler method signature:
@Component (via @ChangeStream’s meta-annotation), so all standard Spring injection patterns apply.
DELETE handler caveat
ForDELETE events, MongoDB does not provide a fullDocument. If you use DOCUMENT_ONLY or DOCUMENT_AND_CONTEXT on @OnDelete, the doc parameter will be null at runtime:
CONTEXT_ONLY for @OnDelete and use ctx.getDocumentKey() to identify the affected document:
See Also
Event Handlers
Dispatch priority, multi-annotation combinations, validation errors.
@ChangeStream
Parent class annotation —
documentType, modes, behavior flags.ChangeStreamContext
The context object passed to every handler.
@Filter
Application-side filtering and signature constraints with
@OnDelete.