2021年1月17日星期日

Use javax.validation outside controller springboot

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

https://stackoverflow.com/questions/65766861/use-javax-validation-outside-controller-springboot January 18, 2021 at 06:58AM

没有评论:

发表评论