Annotations from javax.validation.constraints not working

后端 未结 15 1378
广开言路
广开言路 2020-11-28 06:23

What configuration is needed to use annotations from javax.validation.constraints like @Size, @NotNull, etc.? Here\'s my code:

15条回答
  •  青春惊慌失措
    2020-11-28 06:33

    in my case i had a custom class-level constraint that was not being called.

    @CustomValidation // not called
    public class MyClass {
        @Lob
        @Column(nullable = false)
        private String name;
    }
    

    as soon as i added a field-level constraint to my class, either custom or standard, the class-level constraint started working.

    @CustomValidation // now it works. super.
    public class MyClass {
        @Lob
        @Column(nullable = false)
        @NotBlank // adding this made @CustomValidation start working
        private String name;
    }
    

    seems like buggy behavior to me but easy enough to work around i guess

提交回复
热议问题