Implementing custom validation logic for a spring boot endpoint using a combination of JSR-303 and Spring's Validator

后端 未结 2 2002
谎友^
谎友^ 2020-12-08 11:55

I\'m trying to implement some custom validation logic for a spring boot endpoint using a combination of JSR-303 Bean Validation API and Spring\'s Validato

2条回答
  •  Happy的楠姐
    2020-12-08 12:39

    Per @M.Deinum - using addValidators() instead of setValidator() did the trick. I also agree that using JSR-303, @AssertTrue method-based annotation specifically for cross fields validation, is probably a cleaner solution. A code example is available at https://github.com/pavelfomin/spring-boot-rest-example/tree/feature/custom-validator. In the example, the middle name validation is performed via custom spring validator while last name validation is handled by the default jsr 303 validator.

提交回复
热议问题