From d93f170f2e82319300b825c0437523353fc3c590 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Wed, 11 Sep 2019 16:19:37 +0200 Subject: [PATCH] GH-1710 Added note on adding custom Validator Resolves #1710 --- docs/src/main/asciidoc/spring-cloud-stream.adoc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/src/main/asciidoc/spring-cloud-stream.adoc b/docs/src/main/asciidoc/spring-cloud-stream.adoc index d9aa5e03a..712833abc 100644 --- a/docs/src/main/asciidoc/spring-cloud-stream.adoc +++ b/docs/src/main/asciidoc/spring-cloud-stream.adoc @@ -510,6 +510,22 @@ public class TransformProcessor { ---- +Similar to Spring MVC you can also benefit from JSR-303/309 compliant validation by annotating your arguments with `@Valid`. + +[source,java] +---- +@StreamListener(Processor.INPUT) + @SendTo(Processor.OUTPUT) + public VoteResult handle(@Valid Vote vote) { + return votingService.record(vote); + } +---- +In the above example the `Vote` object and its individual fields will be validated according to the rules set by you (e.g., `@NotBlank`, `@Min`/`@Max` etc.). + +NOTE: Spring Cloud Stream does NOT provide a default `org.springframework.validation.Validator` to avoid potential +conflicts with validators provided by other frameworks that may be part of your application (e.g., MVC), +therefore you may need to provide your own validator by configuring a bean of type `org.springframework.validation.Validator`. + ==== Using @StreamListener for Content-based routing Spring Cloud Stream supports dispatching messages to multiple handler methods annotated with `@StreamListener` based on conditions.