I have a model with a field annotated with @NotNull
public class Employee {
@NotNull
private String name;
//other fields and getters/setters
}
But I don't have controllers. All I want to do is invoke validation on Employee
model either when this method is invoked (this method is in a class that's a Spring component), or manual validation.
When using controllers, I could have annotation handler method with @Valid Employee emp
followed by BindingResults
. But I don't have controllers.
Or in some scenarios, I could have implemented Validator
interface, And then used a combination of BeanPropertyBindingResult
and ValidationUtils.invokeValidator
. But again, in this case, That @NotNull
on model Employee
would not be invoked unless I add validation for it in Validator
implementation.
Is there another way?