I'm trying to validate a class outside of the controller using javax.validation and generating an exception of type MethodArgumentNotValidException. I reviewed the following forums, but not so far they have not been helpful:
Manually call Spring Annotation Validation Outside of Spring MVC
Using Spring Validator outside of the context of Spring MVC
What I want to achieve is the following
public class ClassTest {
@NotEmpty
private String property1;
@NotNull
private String property2;
}
In my validations class do the following (is not a controller), propagating the generated exception (NotNull, NotEmpty, NotBlank, Pattern, others)
void validationClass(boolean value) {
ClassTest classTest = new ClassTest();
if (value) {
//perform class validation
errors = validation(classTest);
throw new MethodArgumentNotValidException(errors);
} else {
//OK
}
}
Thanks for your help