In Springboot project, when I try to add @Validated on controller method, it worked.But now I want to add it on a common method, then failed.
Try to add @Validated on controller method, it worked
public class TaskValidator {
private static final Logger logger = LogManager.getLogger("TaskValidatorLogger");
public void validateTest(@Validated Test test) {
logger.info("Validate: {}", test.getName());
}
public static void main(String[] args) {
new TaskValidator().validateTest(new Test());
}
}
@Data
public class Test {
@NotNull(message = "name can not be null")
private String name;
}
It should throw an MethodArgumentNotValidException but not.