Validating resources using bean validation support

After introducing the request-payload data binding process, we must talk about validation.

Getting ready

The goal of this recipe is to show how to get Spring MVC to reject request body payloads that are not satisfying a bean validation (JSR-303) or not satisfying the constraints of a defined Spring validator implementation.

After the Maven and Spring configuration, we will see how to bind a validator to an incoming request, how to define the validator to perform custom rules, how to set up a JSR-303 validation, and how to handle the validation results.

How to do it…

  1. We added a Maven dependency to the hibernate validator:
    <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> ...

Get Spring MVC: Designing Real-World Web Applications now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.