O'Reilly logo

Spring MVC Beginner’s Guide by Amuthan G

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – combining Spring and bean validations

You need to write the previous bean validations again in a classic Spring-based validation, which is not a good idea, but thanks to the flexibility and extensibility of Spring validation, you can combine both a Spring-based validation and bean validation together with a little extra code. Perform the following steps:

  1. Create a class called ProductValidator under the com.packt.webstore.validator package in the source folder src/main/java. Then, add the following code into it:
    package com.packt.webstore.validator; import java.util.HashSet; import java.util.Set; import javax.validation.ConstraintViolation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.Errors; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required