GH-1710 Added note on adding custom Validator

Resolves #1710
This commit is contained in:
Oleg Zhurakousky
2019-09-11 16:19:37 +02:00
parent 752cf6003c
commit d93f170f2e

View File

@@ -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.