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:
Create a class called
ProductValidator
under thecom.packt.webstore.validator
package in the source foldersrc/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; import org.springframework.validation.Validator; import com.packt.webstore.domain.Product; public class ProductValidator implements Validator{ @Autowired private javax.validation.Validator beanValidator; private Set<...