In my previous tutorial I have shown how to validate input data coming from client or end user to Spring REST Controller. Now in this tutorial I will show you how to validate data in Spring Service Layer.
In this tutorial I will show you how you can validate your input data while working with REST service.
Please go through the tutorial Documenting Spring REST API with Swagger 2
In this example, I will show you how to build a bean validator for
User model object.In my previous example, Spring MVC Custom Validator, I have shown how to validate user input.
Validating input received from the user to maintain data integrity is an important part of application logic.
The Bean Validation model is supported by constraints in the form of annotations placed on a field, method, or class of a JavaBeans component, such as a managed bean.
Constraints can be built in or user defined. User-defined constraints are called custom constraints. Several built-in constraints are available in the javax.validation.constraints package. You can read more on bean validation JavaBeans Validation