Spring Boot JSR-303/349 configuration

前端 未结 3 1200
北海茫月
北海茫月 2021-02-06 06:22

In my Spring Boot 1.5.1 application I\'m trying to configure support of JSR-303 / JSR-349 validation.

I have added a following annotations @NotNull @S

3条回答
  •  被撕碎了的回忆
    2021-02-06 06:51

    The constraint annotations are meant to applied to JavaBeans. See http://beanvalidation.org/1.0/spec/#constraintsdefinitionimplementation-constraintdefinition

    You have the constraint annotation @NotNull, @Size, etc. applied within the DAO. You must create a Java Bean, e.g. "Person", that wraps those attributes (name, description, etc.), then pass "Person" as a parameter to the Controller method. If you need to use a DAO instead of a controller, it will need to be instrumented to perform the validation. You may be on your own in that regard with regard to AOP, etc., unless something has changed since this post: http://forum.spring.io/forum/spring-projects/container/82643-annotation-driven-jsr-303-validation-on-service-and-dao-tier

    Update: Well, looks like it (method level validation JSR-349) is supported now see http://blog.codeleak.pl/2012/03/how-to-method-level-validation-in.html for an example, similar to Arpit's answer. Updated title of question to reflect this latest JSR.

提交回复
热议问题